Highcharts:如何免除一系列重绘缩放计算? [英] Highcharts: How to exempt a series from redraw zoom calculations?

查看:135
本文介绍了Highcharts:如何免除一系列重绘缩放计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个 jsfiddle 中,每次系列的可见性时,图表都有很好的缩放效果

但是,当我添加UpperLimit系列时,由于该系列具有最低和最高的x值,因此此效果将丢失。



如何让图表放大我选择的系列,并让其他系列不影响缩放边界?

 <$ c 
name {'UpperLimit',
color:'#FF0000',
dashStyle:'ShortDash',
showInLegend:false,
// affectZoomBox :假,//没有这样的东西:(
数据:[
[1,100],
[10,100]
]
},


解决方案

我不认为可以使用该系列的配置。但是,如果您愿意进行一些攻击,则可以从轴心极限的计算中排除一个或多个系列:

  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 ++){
//过滤出您不希望包含在计算中的系列
if (originalSeries [i] .name!='UpperLimit'){
series.push(originalSeries [i]);
}
}
axis.series = series;

axis.oldGetSeriesExtremes();

axis.series = originalSeries;
}

该代码显示了如何覆盖 getSeriesExtremes 轴对象上的函数。该方法被一个包装器取代,该包装器删除应该排除的系列,然后调用原始函数,然后将原始系列恢复到轴。

这显然是一种破解。然而,它在我的机器上工作......


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]
    ]
},

解决方案

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

这篇关于Highcharts:如何免除一系列重绘缩放计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆