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

Nik*_*kos 4 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 
            }
        }
    }
},
Run Code Online (Sandbox Code Playgroud)

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

小智 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);
             }
         }
     }
 }
Run Code Online (Sandbox Code Playgroud)


oll*_*cua 0

看起来 highcharts 实际上在回调期间将 xAxis 对象的所有属性设置为 null。您不需要这样做,尽管您可能只需注释掉给出错误的行就可以了