Basic data format
Flot data format is consist of multiple data seires array, like the following format.
[series1, series2, series3, ...]
[x, y]
var data = [ [x1, y1], [x2, y2], [x3, y3], [x4, y4] ];
var data_integer = [ [0, 5], [1, 10], [2, 15], [3, 20] ]; var data_float = [ [1, 5.5], [2.5, -10], [4.5, 15], [6, -20.3] ]; var data_null = [ [1, 5.5], [2.5, null], [4.5, 15], [6, null] ];
Below shows how to take parameters into function when calling $.plot (label attribute can be omitted, but data attribute must be specified)
$.plot(placeholder,[ { label: "line1", data: [ [0, 5], [1, 10], [2, 15], [3, 20] ] } ], options);
Bar chart with null value
Time series data format
If you`re using time series format as data, In addition to convert time into javascript timestamps format, you also need to set axis.mode value to "time" in the options, and include jquery.flot.time.js plugin, below shows you how to use time series.var rawData = [ [1325347200000, 60], [1328025600000, 100], [1330531200000, 15], [1333209600000, 50] ]; var options = { xaxis: { mode: "time" } } $.plot($("#placeholder"),[ { data: rawData } ], options);
Time series line chart
Multiple data series format
Data formats we mentioned above are all have single data seires, but there are times that we need to use multiple data series, the following code shows you how to do it.var rawData_1 = [ [1325347200000, 60], [1328025600000, 100], [1330531200000, 15], [1333209600000, 50] ]; var rawData_2 = [ [1325347200000, 5], [1328025600000, 12], [1330531200000, 7], [1333209600000, 25] ]; var dataset = [ { label: "Sales", data: rawData_1 }, { label: "Profits", data: rawData_2 } ]; $.plot($("#placeholder"), dataset, options);
var dataset = [ { series1 }, { series2 }, { series3 }, .... ];
Mutiple data series chart