How to set Extremes in xAxis event handler?

I try setExtremes in the xAxis event handler below and I get a Uncaught TypeError. How can I setExtremes in an xAxis event handler?

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

Any help or workaround would be greatly appreciated. Thanks.

+4
source share
2 answers

I know that this is a bit late, I just wanted to add my answer to future visitors.

Highchart does not allow calling setExtremes inside the setExtremes event handler to avoid an infinite loop. That is why you get an error.

However, you can insert a timeout to get around this protection:

  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); } } } } 
+5
source

It appears that highcharts actually sets all the properties of the xAxis object to null for the duration of the callback. You do not need to do this, although you can just comment on the line giving the error and be fine

0
source

Source: https://habr.com/ru/post/1478875/


All Articles