How to Sum series in Highcharts & Highstocks
This quick code will do the trick and add a nice sum of all series values in the legend label for each series
1 2 3 4 5 6 7 8 9 10 11 |
legend: { enabled: true, labelFormatter: function() { var count = 0; for (var i = 0 ; i < this.yData.length; i++) { count += this.yData[i]; } return this . name + ' [' + count + ']'; } } |
Quick explanation of Highcharts legend parameters
labelFormatter : function() { } : called by Highcharts to make legend label, for each item, return the text for the legend builder.
this.yData : contains series data, in a Javascript array.
this.name : series label, defined in the series array on your chart definition.
Hope this help