Skip to content Skip to sidebar Skip to footer

Flot How To Know The X Axis Points In Dynamic Data

I am using flot jquery library to draw charts. when my chart has a specific number of columns, I can set the x values for my points. but now I have a dynmic data. so how can I know

Solution 1:

When using $.plot(holder, data, chartOptions);, save the plot with a variable.

Declare var plot; globally,

and then call like this: plot = $.plot(holder, data, chartOptions);.

You can grab the data from the plot like this:

var datasets = [];
var xData = [];

datasets = plot.getData();    //this returns an array of all datasets//goes through each series of datafor (var i = 0; i < datasets.length; i++){
    //picks the series with label of "label 1"if (datasets[i].label == "label 1"){
        //copies x coordinates from the series into xDatafor (var j = 0; j < datasets[i].data[j].length; j++){
            xData.push(datasets[i].data[j][0]);               //if you want y coords, use datasets[i].data[j][1]
        }
    }
}

Post a Comment for "Flot How To Know The X Axis Points In Dynamic Data"