I am trying to find a way to parse my data format so that it could be recognized by HighStocks. My data fetched from the server is in such format:
var data = [
{
"dt":"2010-06-10 14:33:39",
"val":98
},
{
"dt":"2010-06-10 14:34:18",
"val":99
},
{
"dt":"2010-06-10 14:34:28",
"val":93
},
{
"dt":"2010-06-10 14:34:38",
"val":79
},
{
"dt":"2010-06-10 14:34:48",
"val":87
},
{
"dt":"2010-06-10 14:34:58",
"val":86
},
{
"dt":"2010-06-10 14:35:08",
"val":79
},
{
"dt":"2010-06-10 14:35:17",
"val":90
}]
From the demo on Highcharts website it accepts format like:
var usdeur = [
[Date.UTC(2003,8,24),0.8709],
[Date.UTC(2003,8,25),0.872],
[Date.UTC(2003,8,26),0.8714],
[Date.UTC(2003,8,29),0.8638],
[Date.UTC(2003,8,30),0.8567],
[Date.UTC(2003,9,1),0.8536],
[Date.UTC(2003,9,2),0.8564],
[Date.UTC(2003,9,3),0.8639],
[Date.UTC(2003,9,6),0.8538],
[Date.UTC(2003,9,7),0.8489]]
So simply saying, how could I format my data 2010-06-10 14:33:39 to Date.UTC(2010,06,10,14,33,39)? Any JavaScript/jQuery method or existing libraries like date.js/moment.js allow me to do that easily (say if I don’t want to use getUTC*() to get the datetime information and then put into Date.UTC())
Thanks in advance.
Why don’t you format it on your sql ? It’s much better than format each point of your chart.
UNIX_TIMESTAMPshould help you.Example:
SELECT UNIX_TIMESTAMP(concat(dateColumn, timeColumn)) * 1000 AS 'dateUTC';