Flot reset zoom
Asked Answered
G

3

5

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.

Glee answered 17/5, 2013 at 16:29 Comment(0)
S
2

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.

Scum answered 28/5, 2013 at 11:51 Comment(0)
H
7

You can also set a double click to reset the zoom function of the Flot chart. It redraws the Flot chart to its original state and can be used with dynamic data.

$("#placeholder").dblclick(function () {
plot = $.plot(placeholder, dataset, options);
});
Holston answered 10/7, 2014 at 15:17 Comment(0)
E
5

You can set the ranges of the axes to null. By setting this, the zoom level will be set so every data point is visible, just like the default zoom level.

Unlike the other solutions, this solution will not construct a whole new plot.

var axes = plot.getAxes(),
    xaxis = axes.xaxis.options,
    yaxis = axes.yaxis.options;
xaxis.min = null;
xaxis.max = null;
yaxis.min = null;
yaxis.max = null;

// Don't forget to redraw the plot
plot.setupGrid();
plot.draw();
Eveevection answered 9/7, 2014 at 9:21 Comment(0)
S
2

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.

Scum answered 28/5, 2013 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.