简体   繁体   English

HighCharts:可以汇总系列数据并在标题中显示?

[英]HighCharts: Possible to summarize series data and show in title?

I'm looking for an answer if it's possible to sum the HighCharts series and show it in the title? 如果可以将HighCharts系列加入并在标题中显示,我正在寻找答案? I'm using JSON data for the series, so if the data looks like this: 我正在使用该系列的JSON数据,所以如果数据如下所示:

[0,0,0,1,1,1,2,2,2,3,3,3]

The sum should of course be: 18. 总和当然应该是:18。

I've tried asking Google but I haven't found anything. 我试过问谷歌,但我没找到任何东西。 I know I could handle it elsewhere but it would be nice to handle it directly inside the HighCharts script. 我知道我可以在其他地方处理它,但直接在HighCharts脚本中处理它会很好。

Thx. 谢谢。

/CRH / CRH

Because you pass an object literal to Highcharts, you best bet might be to do something like this: 因为你将对象文字传递给Highcharts,你最好的选择可能就是做这样的事情:

http://jsfiddle.net/WRa43/ http://jsfiddle.net/WRa43/

var data = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];

$('#container').highcharts({
    series: [{
        data: data
    }],

    title: {
        text: "Total is " + data.reduce(function(i,a) { return i+a; })
    }
});

Reference for array.reduce array.reduce的参考

How about summing it in Javascript and then using the result when creating the title? 如何在Javascript中对它进行求和,然后在创建标题时使用结果?

var sum = 0;
for(var i in series)
    sum += i;

Then, just set the title: 然后,只需设置标题:

chart = new Highcharts.Chart({
    ...

    title: {
        text: 'SUM: ' + sum
    },

    ...
)};

That should work, right? 那应该有用,对吗?

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

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