javascript - 将 JSON 与 Dygraph 和日期时间结合使用

标签 javascript jquery ajax json dygraphs

我正在使用 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/

相关文章:

javascript ajax没有按时更新变量

jquery - 使用 AJAX 加载 div 内容时 HTML5 音频不循环

javascript - 即使在定义绑定(bind)后也无法读取未定义的属性 'setState'(this.submit)

javascript - string.split() 之后 Switch/case 没有响应

javascript - 为什么只有在集合不存在时 MongoDB 才插入记录的速度较慢?

javascript如何在连字符后使所有字符串变为斜体?

jquery - 折叠 Bootstrap 导航栏中的全宽输入

javascript - removeAttr ("style") 不起作用

javascript - 使用 jQuery .when .then

php - 使用 php 和 mysql 进行 Ajax 分页