Reputation: 19103
I am using setExtremes to zoom in on detail in a chart, as well as allowing the user to zoom 'x,y' by selecting in the chart. When the user zooms, they get a 'reset zoom' button, however when I call setExtremes, I don't.
Is there a way for me to force the 'reset zoom' button to appear programatically ?
UPDATE:
calling
if( !chart.resetZoomButton ) {
chart.showResetZoom();
}
inside the afterSetExtremes event handler makes the button appear, but clicking it doesn't do anything.
UPDATE:
Rather than calling setExtremes, I've changed to calling
chart.xaxis[0].zoom(minx, maxx); chart.yaxis[0].zoom(miny, maxy); chart.redraw();
This has the same affect as the user zoomin in by selecting on the chart.
Upvotes: 12
Views: 12772
Reputation: 1199
If you are using setExtremes you can also set min and max to null to reset:
chart.xAxis[0].setExtremes(null, null)
Upvotes: 0
Reputation: 7128
This approach works well:
if (!$('.highcharts-button').length) {
chart.showResetZoom();
}
This is assuming that the only button that might show is the "Reset Zoom" button. If it is already there, don't show another.
If you don't do this check, a new button is added each time you call showResetZoom()
. Clicking the visible (most recent) button resets the zoom and removes the button but the older buttons are still visible and do nothing.
Upvotes: 1
Reputation: 1569
Just had a look around the HighCharts source code, it looks like this may work out for you:
chart.showResetZoom();
Also, in order for the button to work correctly, you should use axis.zoom instead of setting the extremes:
axis.zoom(newMin,newMax);
Let me know if it works!
Upvotes: 15
Reputation: 26320
You can use showResetZoom
, but you have to check if the reset button is already visible, otherwise it won't desapear.
if( !chart.resetZoomButton ) {
chart.showResetZoom();
}
Upvotes: 8