Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts 'Reset Zoom' after calling setExtremes

Tags:

highcharts

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.

like image 696
SteveP Avatar asked Mar 21 '13 14:03

SteveP


3 Answers

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!

like image 53
MatthewKremer Avatar answered Nov 10 '22 13:11

MatthewKremer


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();
}
like image 38
Ricardo Alvaro Lohmann Avatar answered Nov 10 '22 13:11

Ricardo Alvaro Lohmann


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.

like image 27
Glen Little Avatar answered Nov 10 '22 14:11

Glen Little