Search code examples
javascriptjqueryjsonflot

Is there a way to graph with jQuery's flot with a data set that doesn't contain x values?


I have large amounts of data formatted in JSON formats, I recently scripted the data to conform to Flot's data set, except for one problem, the data has no x values.

EG:

{
  label: "testMetric1",
  data: [12,314,123,41]
}

I want to simply graph these values as y values. Is there a way to tell Flot to just assume the x series will be sequential (i.e. graph 12 at x = 1, graph 314 at x = 2, etc.)


Solution

  • There isn't a way to automatically have it do that, no.

    So before you feed your data to flot, do something like this:

    var data = [12,314,123,41]; 
    var new_data = [];
    
    for (var i=0;i<data.length;i++){  
     new_data.push([i,data[i]]); 
    }
    
    //then call flot here with new_data