我正在使用 Dygraph 和 jQuery,如下所示:
$.getJSON('/myurl/for/jsondata', function(data) {
g = new Dygraph(document.getElementById("demodiv"), data, {});
});
响应数据如下:
[[1372951380.0, 82.31065525957484], [1372951440.0, 85.25771431214908], [1372951500.0, 81.12563963030715], [1372951560.0, 80.87068966263206], [1372951620.0, 80.18137775897438], [1372951680.0, 81.46331467662664], [1372951740.0, 77.4216130457947]]
我的问题是 dygraph 似乎没有将时间戳作为日期。它显示图例的编号。我尝试使用 ValueFormatter、ValueParser 和 AxisLabelFormatter 但没有成功(也许我做错了?)
有人知道如何启用日期时间而不走入所有数据并手动转换时间戳吗?
最佳答案
你尝试过吗:
var utcSeconds = 1372951380;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
看看http://dygraphs.com/data.html并滚动到数组( native 格式)
关于javascript - 将 JSON 与 Dygraph 和日期时间结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17574245/