Eli : Memcached, MySQL, Highcharts

Tag - Javascript

Tag - Javascript

Summing Graph Data by Series in Highcharts/Highstocks

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

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

Javascript function setInterval() with custom parameters

Javascript method

The setInterval() method calls a function or evaluates an expression at specified intervals in milliseconds
One tricky thing is passing parameters to the function called as documentation is hard to find.

Passing Parameters to setInterval()

Make an anonymous function inside setInterval()

function load(functionParameter) {
    //function called by setInterval()
}
...
var customParameter;
setInterval(function() { load(customParameter); },  1000);


Hope this help you save time