如何在xAxis事件处理程序中设置Extremes?

时间:2013-05-02 21:53:34

标签: highcharts highstock

我正在尝试在下面的xAxis事件处理程序中设置Extremes,我得到了Uncaught TypeError。 如何在xAxis事件处理程序中设置Extremes?

xAxis: {
    events: {
        setExtremes: function (e) {
            if (e.trigger === "navigator") {
                    forceRebuildSeries(); //Get all data points

                    // Set Extremes (redisplay with new data points)
                    this.chart.xAxis[0].setExtremes(e.min, e.max);  //Uncaught TypeError: Property 'setExtremes' of object #<Object> is not a function 
            }
        }
    }
},

我将不胜感激任何帮助或解决方法。 感谢。

2 个答案:

答案 0 :(得分:5)

我知道这有点晚了,只是想把我的答案添加到未来的访客中。

Highchart不允许从setExtremes事件处理程序中调用setExtremes,以避免无限循环。这就是你得到错误的原因。

但是,您可以插入超时以解决此问题:

 xAxis: {
     events: {
         setExtremes: function (e) {
             if (e.trigger === "navigator") {
                 var c = this;
                 setTimeout(function() {
                     forceRebuildSeries(); //Get all data points

                     // Set Extremes (redisplay with new data points)
                     c.chart.xAxis[0].setExtremes(e.min, e.max);  

                 }, 1);
             }
         }
     }
 }

答案 1 :(得分:0)

看起来highcharts实际上是在回调期间将xAxis对象的所有属性设置为null。你不应该这样做,虽然你可能只是注释出错误的行并且没问题

相关问题