3

我从我的 WebAPI 返回了 json。

[{"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 示例会有所帮助。

4

2 回答 2

1

尝试这个:

+new Date('2013-03-16T00:16:00.387') / 1000 // 1363392960.387
于 2013-03-16T12:52:22.537 回答
0
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);
}
于 2013-03-16T13:00:55.157 回答