你能告诉我怎么做吗?我收集数据并使用 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/