I have a JSON array that's been returned from an AJAX function. The array looks like this:
{
"date":[
[
"2015-05-29",
"2015-05-12",
"2015-04-30",
"2015-03-30",
"2015-02-27",
"2015-02-26"
]
],
"close":[
[0,3,1,1,0,0]
],
"high":[
[1,3,2,1,0,1]
],
"low":[
[0,-1,0,-1,-1,-1]
]
}
I need to take the 'dates' and the 'close' items and blend them into something that will look like this, for JQPlot
var line1=[['2008-06-30 8:00AM',4], ['2008-7-30 8:00AM',6.5], ['2008-8-30 8:00AM',5.7], ['2008-9-30 8:00AM',9], ['2008-10-30 8:00AM',8.2]];
I figure I need to loop something like this but I'm not sure how to join the values into the new date format above?
s3 = obj["close"][0];
dates = obj["date"][0];
for( var i = 0; i < dates.length; i++ ){
//not sure what to put here
}
// the data object you get back from your ajax
var data = {"date":[["2015-05-29","2015-05-12","2015-04-30","2015-03-30","2015-02-27","2015-02-26"]],"close":[[0,3,1,1,0,0]],"high":[[1,3,2,1,0,1]],"low":[[0,-1,0,-1,-1,-1]]}
var time = " 8:00AM"
var dates = data.date[0]
var s3 = data.close[0]
// make sure the data is valid
// (`dates` and `s3` must have the same length in order to join them)
if (dates.length !== s3.length) {
throw new Error('oh no! the data is invalid')
}
var line1 = []
for(var i = 0; i < dates.length; i++) {
line1.push([dates[i] + time, s3[i]])
}