Highcharts: How to exempt a series from redraw zoo

2019-09-15 06:01发布

In this jsfiddle the chart has a nice zoom effect every time the visiblity of a series is toggled.

But when I add the UpperLimit series this effect is lost because that series has the lowest and highest x-values.

How can I make the chart zoom in on the series of my choice and keep other series from affecting zoom boundaries?

{
    name: 'UpperLimit',
    color: '#FF0000',
    dashStyle: 'ShortDash',
    showInLegend: false,
    //affectsZoomBox: false, //No such thing :(
    data: [
        [1, 100], 
        [10, 100]
    ]
},

1条回答
混吃等死
2楼-- · 2019-09-15 06:31

I don't think it is possible using configuration of the series. However, if you are willing to hack a bit it will be possible to exclude one or more series from the calculation of axis extremes:

chart.xAxis[0].oldGetSeriesExtremes = chart.xAxis[0].getSeriesExtremes;
chart.xAxis[0].getSeriesExtremes = function() {
    var axis = this;
  var originalSeries = axis.series;
    var series = [];

  for (var i = 0; i < originalSeries.length; i++) {
    // Filter out the series you don't want to include in the calculation
    if (originalSeries[i].name != 'UpperLimit') {
        series.push(originalSeries[i]);    
    }
  }
    axis.series = series;

  axis.oldGetSeriesExtremes();

  axis.series = originalSeries;
}

The code shows how to overwrite the getSeriesExtremes function on the axis object. The method is replaced with a wrapper that removes the series that should be excluded, then calls the original function and then restores the original series to the axis.

This is clearly a hack. However, it works on my machine...

查看更多
登录 后发表回答