我有json从我的WebAPI返回。
[{"Total":7,"ActivityType":1,"TimeStamp":"2013-03-16T00:16:00.387","Id":1,"State":"Alabama"},{"Total":4,"ActivityType":1,"TimeStamp":"2013-03-16T00:31:00.41","Id":1,"State":"Alabama"}]
Flot需要这样的数据
var d1 = [[1262818800,100],[1262732400,100],[1262646000,100]];
我需要将时间戳转换为刻度或javascript中的任何内容,以便我可以使用它来绘制我的图形。如果有人能帮助我,我会很感激。jsFiddle的例子会有所帮助。
试试这个:
+new Date('2013-03-16T00:16:00.387') / 1000 // 1363392960.387
var arr = [{
"Total": 7,
"ActivityType": 1,
"TimeStamp": "2013-03-16T00:16:00.387",
"Id": 1,
"State": "Alabama"
}, {
"Total": 4,
"ActivityType": 1,
"TimeStamp": "2013-03-16T00:31:00.41",
"Id": 1,
"State": "Alabama"
}];
var d1 = [];
for (var i = 0, len = arr.length; i < len; i++ ) {
var t = [new Date(arr[i].TimeStamp).getTime() / 1000,100]
d1.push(t);
}