Walker
Walker

Reputation: 134443

Loading 'flot' (graphing plugin) with a default zoom value?

I'm trying to create a data vs time graph which allows the user to zoom in/out to large/smaller time periods. You can see an example of one such graph here: http://people.iola.dk/olau/flot/examples/visitors.html

While the API has been a breeze for setting up that level of functionality, I've gotten stock when trying to figure out how to create a default "zoom" value - to, for instance, set the default zoom to the past 30 days (while retaining the ability for the user to zoom out and view an entire year of data).

Does anyone have any experience or know a way of doing this? Or is it a matter of digging into the source code and customizing it?

Thanks! Walker

Upvotes: 1

Views: 1622

Answers (1)

rossdavidh
rossdavidh

Reputation: 1996

If you look at the code in, for example, flot zooming example, and you modify the definitions of the variable "options" thusly:

var options = {
    legend: { 
        show: false 
    },
    series: {
        lines: { 
            show: true 
        },
        points: { 
            show: true 
        }
    },
    yaxis: { 
        ticks: 10,
        min: -0.8,
        max: 0.4
    },
    selection: { 
        mode: "xy" 
    }
};

... you'll find that the graph starts out with this level of y-axis zoom, but the smaller graph still retains the full range that you can zoom out to if you want. The lines added are in the "yaxis" definition, "min" and "max". You would do something similar for "xaxis" if you want to pre-zoom the x-axis.

Upvotes: 3

Related Questions