My goal is to have a new option on the Y axis of a line chart that allows to toggle between regular Y data series (e.g. [1,2,3]) or the accumulation of the original data series ([1,3,6]).
I started by wrapping the processData method as follows
(function (H) {
H.wrap(H.seriesTypes.line.prototype, 'processData', function(force) {
var yData = this.yData;
for (var i = 1; i < yData.length; i++) {
yData[i] = yData[i] + yData[i-1];
};
//alert(this.yData);
force.apply(this, Array.prototype.slice.call(arguments, 1));
});
} (Highcharts));
The this.yData gives me access to the right data and the rest is pretty straight forward. When plotted I do see the Y-axis limit change as expected, but the data points are still drawn according to their original values (here's a fiddle: http://jsfiddle.net/oL3LfrLr/)
I suspect it might be some scoping issue but I don't really see what's wrong in the above. Any tips?
Why wrap processData?
Not sure to be honest. I'm fairly new to javascript and HighCharts and this is my first extension. I looked at the Waterfall Series which does part of what I want and from the source of that I 'guessed' it would either be the translate or processData method. The latter sounded most promising so I started there.