Grand Totals in HighCharts Pie Chart Legend

会有一股神秘感。 提交于 2019-12-05 14:59:27

You could hack this in by appending the total to the last legend item.

chart: {
  events: {
    load: function(event) {
      $('.highcharts-legend-item').last().append('<br/><div style="width:200px"><hr/> <span style="float:left"> Total </span><span style="float:right"> ' + total + '</span> </div>')
    }
  }
}

Fiddle here.

I would actually add the total as another entry in the data array, with a null value and a label attribute. Something like this:

legend: {
    labelFormatter: function() {
        return this.name + ': ' + this.y_label;
    },
},
// ...
series: [{
    type: 'pie',
    data: [
        {'name': 'Real Estate', 'y': 12.55, 'y_label': 12.55},
        // ...
        {'name': 'Total', 'y': null, 'y_label': 100, 'color': 'transparent'}
    ]
}]

Fiddle here: http://jsfiddle.net/Aeon/9cZKg/1/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!