Highcharts: How to exempt a series from redraw zoom calculations?

心不动则不痛 提交于 2019-12-12 00:40:07

问题


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:


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...



来源:https://stackoverflow.com/questions/37412442/highcharts-how-to-exempt-a-series-from-redraw-zoom-calculations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!