简体   繁体   English

Javascript未显示在Oracle APEX Donut图表中间的总价值

[英]Javascript not showing up total value in middle of Oracle APEX Donut chart

I am trying use below code (found from a forum) as JavaScript initialization code in Oracle APEX Donut chart to display total value in middle. 我正在尝试使用下面的代码(从论坛找到)作为Oracle APEX Donut图表中的JavaScript初始化代码,以在中间显示总价值。 But the result showing up only the Text "Total" in middle of the chart and does not show any numerical value. 但是结果仅在图表中间显示文本“总计”,而不显示任何数值。 Can anyone help me out in spotting the error from the below code ? 谁能帮我找出以下代码中的错误? I am new to Javascript and have very less knowledge about the same. 我是Java的新手,对此一无所知。

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
}

return options; 返回选项; } }

if I correct understood, try to fix it, add to centerCallback , 如果我理解正确,请尝试修复它,并将其添加到centerCallback

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

Could you try this 你可以试试这个吗

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

Add below statement in this.pieSliceLabel = function(dataContext){} this.pieSliceLabel = function(dataContext){}中添加以下语句

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

Update the below innerHTML code in this.centerCallback = function(dataContext){} this.centerCallback = function(dataContext){}中更新以下innerHTML代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM