我正在尝试找到一种方法来解析我的数据格式,以便 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*()
用来获取日期时间信息然后放入Date.UTC()
)
提前致谢。