Abrissirba
Posts: 11
Joined: Mon Mar 27, 2017 11:30 am

How to know if zoom is active

Is it possible to know if the chart has been zoomed in or not? The best scenario for me would be if there are some boolean indicating if it is zoomed in or not. I guess that there already might be some variable for this since the Reset zoom button is shown when the chart i zoomed in.
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: How to know if zoom is active

Hi, Abrissirba!

Exactly. You can simply check if the zoomButton is shown. I prepared a simple example for you: https://jsfiddle.net/BlackLabel/gbwkaL7h/

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead
Abrissirba
Posts: 11
Joined: Mon Mar 27, 2017 11:30 am

Re: How to know if zoom is active

Thanks :), is that available from the chart object or do I need to save the value in afterSetExtremes?

Is it possible to write custom logic for how Reset zoom should work?
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: How to know if zoom is active

Abrissirba,

The problem is not "where to save the value" but "when should we check whether the zoom is active". It is available from the chart object chart.resetZoomButton: https://jsfiddle.net/BlackLabel/ew2syvmL/
(in afterSetExtremes function this = xAxis and chart = xAxis.chart)

But the real question is when you want to check whether chart is zoomed. If you want to check it every zoom action that afterSetExtremes event is best for that. But if you want to check if e.g on click, you don't need afterSetExtremes event: https://jsfiddle.net/BlackLabel/62ufzpvc/

When it comes to a custom logic for reset - do you want to go back 1 zoom level after clicking the button instead of the whole reset? This is a common question.
Rafal Sebestjanski,
Highcharts Team Lead
may.tau
Posts: 2
Joined: Thu Jan 30, 2020 5:35 pm

Re: How to know if zoom is active

Any idea how to implement this, if I zoom around with the mousewheel? (highmaps solution)
With this type of zooming the Rest Zoom button doesn't appear on zoom-in. Actually I hoped to render it upon the afterSetExtremes event, but then it gets also called on full zoom-out.
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: How to know if zoom is active

Hi,

I am not sure if I understood you correctly. You mean to render the button from this thread, right? viewtopic.php?f=12&t=40143

Are you looking for something like this? https://jsfiddle.net/BlackLabel/agt62epf

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead

Return to “Highcharts Usage”