javascript - dygraph 仅显示上个月的数据

标签 javascript dygraphs

你能告诉我怎么做吗?我收集数据并使用 dygraphs 将其可视化。 .txt 文件中收集的数据是温度和日期格式,例如

2018-04-19 15:47.12.7
2018-04-19 15:48.12.5
2018-04-19 15:49, 12.5
2018-04-19 15:50,12.3
2018-04-19 15:51.12
2018-04-19 15:52.12
2018-04-19 15:53,12.7
2018-04-19 15:54.12
2018-04-19 15:55,12.8
2018-04-19 15:56.12.8
2018-04-19 15:57,12.6
2018-04-19 15:58.12.7
...
2018-07-09 11:59 24.1

如何在 dyhraph 中制作图表只显示上个月的数据而不是整个月的数据?因为现在图表显示了几个月以来的所有内容。

<html>
<head>
<script src="js/dygraph-combined.js"></script>
<link rel="stylesheet" href="js/dygraph.css" />

</head>
<body>

<div id="graphdiv2"
  style="width:550px; height:300px;"></div>
<script type="text/javascript">

    g2 = new Dygraph(
    document.getElementById("graphdiv2"),
    "xxxxxxxxxxxx.txt",
    {
    title: '<embed src="xxxxxxxxxx.php" width="500" height="40"  >',
    legend: 'always',
    ylabel: 'Temperature (C)',
    xlabel: 'Date (Month)',
    rollPeriod: 10,
    showRoller: true,
    color: "red",
    valueRange: [-10,40],<----->//zakres
}
 );
</script>

</body>

</html>

最佳答案

尝试传入 dateWindow选项:

new Dygraph(div, data, {
  // ... other options ...
  dateWindow: [
    +new Date() - 30 * 24 * 60 * 60 * 1000,  // one month ago
    +new Date()  // today
  ]
});

关于javascript - dygraph 仅显示上个月的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51242915/

相关文章:

javascript - 如何在屏幕最后显示最近上传的图片?

javascript - 试图找到一种方法将 "listen"发送到外部网页上的事件

php - 将 ajax 调用获取的数据返回到另一个函数

php - 在 php 脚本和 dygraphs 中使用 new date()

css - dygraph 不加载本地 css 文件

php - 为什么即使在发送无缓存 header 后页面仍在缓存?

javascript - 中途更改 Dygraphs 系列的颜色

dygraphs - 限制y轴范围

javascript - XUL Richlistbox选择问题

JavaScript 获取然后更改类(带变量)