See this example custom approximation provided by Highcharts: http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/stock/plotoptions/series-datagrouping-approximation
dataGrouping: {
approximation: function () {
return this.dataGroupInfo.length;
},
forced: true
},
Scroll the selection from left to right.
Notice that dataGroupInfo.length
increases and decreases as the dataGroup
enters and exits the chart area. I believe this is due to the dataGroup
being cropped by the chart area.
I have attempted to resolve this issue by setting cropThreshold
to Infinity without success (It seems unrelated).
I need to create a custom approximation that is not cropped by the chart area.
To complicate things a bit, my custom approximation is for series[0]
and is an average. In my case, it is the result of series[0]
divided by series[1]
.
My current attempt is the following:
http://jsfiddle.net/rbwc217s/
approximation: function(arr) {
var numerator = 0,
denominator = 0;
if (arr.length !== 0) {
var start = this.xData.indexOf(this.processedXData[0]) + this.dataGroupInfo.start,
slicedArr = this.chart.series[1].yData.slice(start, start + (arr.length));
for (var i in arr) {
numerator += arr[i];
denominator += slicedArr[i];
};
};
return denominator !== 0 ? Math.round((numerator / denominator) * 1000) / 1000 : null;
},
It works as expected - except on the edge of the chart area. Again, I believe this is due to the dataGroup
being cropped by the chart area.
Any help is appreciated.
Thank you.