的Javascript没有显示在Oracle APEX圆环图的中间合计值

问题描述 投票:0回答:2

我试图在甲骨文APEX圆环图下面的代码使用(从论坛中发现),如JavaScript初始化代码在中间显示总价值。但结果显示出来只有文本“总计”在图表的中间,不显示任何数值。任何人都可以帮助我从下面的代码察觉的错误?我是新来的Javascript和具有大致相同的非常少的知识。

function( options ){ 

  var total;  
  this.pieSliceLabel = function(dataContext){

  var series_name;
       percent = Math.round(dataContext.value/dataContext.totalValue*100);
       total = Math.round(dataContext.totalValue);

    if ( dataContext.seriesData ) {
        series_name = dataContext.seriesData.name;
    } else {
        series_name = 'Other';
    }
    document.getElementById("myDiv").innerHTML = Math.round(dataContext.totalValue);
    return series_name + " " + percent + "% ( " + dataContext.value + " )";
} 
// Set chart initialization options 
options.dataLabel = pieSliceLabel; 

this.centerCallback = function(dataContext){
  var pieElem = document.createElement('div');

  pieElem.innerHTML = 
  '<div id="myDiv" style="position:absolute;text-align:center;font-size:16px;">' +
      'Total' +' '+ total +
  '</div>';

  var outerDiv = pieElem.children[0];

  var innerBounds = dataContext.innerBounds;

  // Outer bounds
  outerDiv.style.top = innerBounds.y + "px";
  outerDiv.style.left = innerBounds.x + "px";
  outerDiv.style.height = innerBounds.height + "px";
  outerDiv.style.width = innerBounds.width + "px";
  outerDiv.style.lineHeight = innerBounds.height + "px";
  return  pieElem;
}

options.pieCenter = {  
          renderer : centerCallback
}

返回选项; }

javascript chart.js oracle-apex oracle-jet
2个回答
0
投票

如果我正确的理解,尝试修复它,添加到centerCallback

var value = dataContext.totalValue;
pieElem.innerHTML = 
      '<div id="myDiv" style="position:absolute;text-align:center;font-size:16px;">' +
          'Total ' + value +
      '</div>';

0
投票

你可以试试这个

function( options ){ 
// will hold the total value, must be global variable
var total;

添加下面this.pieSliceLabel = function语句(的DataContext){}

    percent = Math.round(dataContext.value/dataContext.totalValue*100);
    total = dataContext.totalValue; //assign to global variable

更新下面innerHTML的代码在this.centerCallback =函数(的DataContext){}

  //updated element
  pieElem.innerHTML = 
      '<div id="myDiv" style="position:absolute;text-align:center;font-size:16px;">' +
          'Total' + total +
      '</div>';
© www.soinside.com 2019 - 2024. All rights reserved.