I'm using jqPlot to build some dynamic graphs.
jqPlot takes a 2D array for its data, thus:
$.jqplot('chartdiv', [[[1, 2],[2,5.12],[3,13.1],[7,33.6],[9,85.9],[21,219.9]]],
{ title:'progress',
axes:{yaxis:{min:0, max:240}},
series:[{color:'#5FAB78'}]
});
The first number is the x axis (in this case 1,2,3,7,9 and 21), the second number is the y axis. chartdiv is the html element where the graph is displayed, the rest is self explanatory.
I want to take data from my localStorage and push it to an array that will allow me to display it as a graph, and I can't work out how to do this.
If my array is declared with
var graphdata = [];
how to I push the data into it? I'm using a loop like this to get to the content:
var dt = new Date();
var today = dt.getDateKey();
var df = getStartDate(period);
var datefrom = df.getDateKey();
var graphdata = [];
alert("Today is " + today + " and the graph will be calculated from " + datefrom);
while (df<=dt) {
dataObject = JSON.parse(localStorage.getItem(df.getDateKey()));
if(dataObject){
var dateposition = df.getDateKey();
console.log("Date is " + dateposition);
console.log("The Weight is " + dataObject.savedobs1);
graphdata.push([dateposition,dataObject.savedobs1]);
}
df.setDate(df.getDate() + 1);
};
console.log("Graph data " + graphdata);
I need to get the dateposition and the data into the chart and I can't work out how to get it into the right format. The console.log of the graph data just gives:
Graph data ,26/04/2014,118,27/04/2014,116,28/04/2014,116,29/04/2014,105
