简体   繁体   English

如何在Highcharts中显示甜甜圈图的系列值的总和?

[英]How to display the total of the series values for a donut chart in Highcharts?

I'm displaying a donut chart using Highcharts and in the middle I've currently got the title; 我正在使用Highcharts显示一个甜甜圈图,中间是我现在得到的标题; 'Transactions' but below that, but still in the middle, I'm trying to show the total number of the series values which should be €8,173.99. “交易”但低于该价格,但仍在中间,我试图显示该系列值的总数,应为€8,173.99。

I thought the following code would work: 我认为以下代码可以工作:

events: {
  load: function(event) {
    var total = 0; // get total of data
    for (var i = 0, len = this.series[0].yData.length; i < len; i++) {
      total += this.series[0].this.y[i];
    }
    var text = this.renderer.text(
        'Total: ' + total,
        this.plotLeft,
        this.plotTop - 20
      ).attr({
        zIndex: 5
      }).add()
  }
},

I see no errors but then again the total is not being displayed. 我没有看到错误,但是再次没有显示总数。 What am I doing wrong? 我究竟做错了什么?

You can see the JSFiddle here http://jsfiddle.net/tobitobetoby/1fqvzpdn/3/ 您可以在这里http://jsfiddle.net/tobitobetoby/1fqvzpdn/3/中看到JSFiddle

The events object should be placed inside chart object. events对象应放置在chart对象内。 As for the adding 'Total' info, I personally think that the better idea is to just set title on load event using Chart.setTitle() function. 至于添加“总计”信息,我个人认为更好的主意是使用Chart.setTitle()函数仅在load事件上设置标题。 Take a look at the below example. 看下面的例子。

API Reference: API参考:
http://api.highcharts.com/highcharts/Chart.setTitle http://api.highcharts.com/highcharts/Chart.setTitle

Example: 例:
http://jsfiddle.net/yt5pj3yf/ http://jsfiddle.net/yt5pj3yf/

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

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