Highcharts 'Reset Zoom' after calling setExtremes

回眸只為那壹抹淺笑 提交于 2021-02-06 09:04:12

问题


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.


回答1:


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!




回答2:


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();
}



回答3:


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.




回答4:


If you are using setExtremes you can also set min and max to null to reset:

chart.xAxis[0].setExtremes(null, null)


来源:https://stackoverflow.com/questions/15550510/highcharts-reset-zoom-after-calling-setextremes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!