Search code examples
flot

Flot reset zoom


I'm using Flot Charts with mouse scroll to zoom in and out. I created a button to call zoomOut() and it works well, but I can't find any solution to how I can zoom out all the way so that it Looks just like when it was first loaded. I don't want to reload that who container because it using ajax to pull data from mysql on refresh.

I Googled but couldn't find anything.


Solution

  • You can save your initial ranges of axes and redraw your plot like in example for navigating. But your code will be look like these:

    // do the zooming
    plotObjectPointer = $.plot(placeholder, plotData,
        $.extend(true, {}, options, {
            xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
            yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
        }));
    

    where ranges will be your initial ranges. To prevent repeated Ajax loading you can use window.localStorage or just another var for storing plotData.