valugi
Posts: 23
Joined: Mon Apr 04, 2011 2:40 pm

zoom detection

What is the correct way to detect if the chart is zoomed-in or not?
Is there a status change for the "reset zoom" button?
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: zoom detection

You can use afterSetExtremes event which detect "changing range". Then recognise if is zoomed by dataMin and dataMax variables, which "keep" data min/max from "displayed" area, but min/max keep from entire series.

Example should be more clear http://jsfiddle.net/sbochan/5bhsM/1/
Sebastian Bochan
Highcharts Developer
valugi
Posts: 23
Joined: Mon Apr 04, 2011 2:40 pm

Re: zoom detection

Thanks, but I need to get the status of the chart from outside the chart. With your suggestion I could try to write a custom variable zoomed_in after the zoom_in happens, but this way I will have to modify a lot of charts with this custom code.
Isn't there any other way to get the status without modifying the chart itself?
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: zoom detection

I'm not sure why you need zoomed_in / zoomed_out variables? In my example I used only variables which are included and used by highcharts.
Sebastian Bochan
Highcharts Developer
valugi
Posts: 23
Joined: Mon Apr 04, 2011 2:40 pm

Re: zoom detection

I need it because I have an external element that interacts with the chart and which wants to know what is the status of the zoom in order to restrict or not some other actions.
I have a trend line generator for series in the chart, which I want to deactivate when the chart is zoomed in, and reactivate it when is back on regular zoom.

Should I record the values for chart.xAxis.min and max that I have when I start and compare later if are the same? Is this better than a boolean somewhere in the chart.options stating the status of the zoom?
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: zoom detection

I need it because I have an external element that interacts with the chart and which wants to know what is the status of the zoom in order to restrict or not some other actions.
So you can use one global variable which will have true or false value, independent on zoom status.

I suggest also to take look at solution with prepareing isZoomed function http://jsfiddle.net/PNE3s/
Sebastian Bochan
Highcharts Developer
valugi
Posts: 23
Joined: Mon Apr 04, 2011 2:40 pm

Re: zoom detection

Thanks again for the suggestion, but this one also requires adding extra code on the chart side.
Take this as a suggestion, and maybe you can add a chart.options variable in the next release.
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: zoom detection

I reccomend to vote for suggestion in our feature system:

http://highcharts.uservoice.com/forums/ ... -parameter
Sebastian Bochan
Highcharts Developer

Return to “Highcharts Usage”