0

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.

  • I think you simply need to set [`series.getExtremesFromAll`](http://api.highcharts.com/highcharts/plotOptions.series.getExtremesFromAll), see demo: http://jsfiddle.net/rbwc217s/1/ Note: it will scale your yAxis to extremes from all points, as the name says ;) But will group all points at the same time, not only the ones within the visible range. – Paweł Fus May 17 '17 at 13:55
  • @PawełFus Thanks! I didn't realize that this had such an effect on datagrouping. Works like a charm! Now, if there is a way to group the data without affecting the yAxis extremes, it would be a perfect solution. I don't always have much vertical real estate, and given the extremes of my data set, portions of the graph appear to be flat lines at large scale. – BusyBusinessAnalyst May 22 '17 at 15:03
  • I think that simple plugin like this: http://jsfiddle.net/rbwc217s/2/ should resolve the issue. As you can see, when calculating series' extremes, we can change `getExtremesFromAll` and restore after extremes are set. – Paweł Fus May 23 '17 at 10:45

0 Answers0