我正在尝试找到一种解析数据格式的方法,以便HighStocks能够识别它。从服务器获取的数据格式为:
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
}]
从Highcharts网站上的演示中,它接受如下格式:
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]]
简单地说,我如何将数据2010-06-10 14:33:39
格式化为Date.UTC(2010,06,10,14,33,39)
?任何JavaScript / jQuery方法或者像date.js / moment.js这样的现有库都允许我轻松地这样做(比如说我不想使用getUTC*()
来获取日期时间信息然后放入{{1} })
提前致谢。
答案 0 :(得分:1)
为什么不在sql上格式化它?它比格式化图表的每个点要好得多
UNIX_TIMESTAMP
应该对你有所帮助
示例强>:
SELECT UNIX_TIMESTAMP(concat(dateColumn, timeColumn)) * 1000 AS 'dateUTC';