【发布时间】:2019-11-21 15:01:54
【问题描述】:
我是 Dygraphs 库的新手,在使用 Dygraph 绘制动态数据方面需要帮助。我在 Dygraph 中看到过这个例子
$(document).ready(function() {
var data = [];
var t = new Date();
var g = new Dygraph(document.getElementById("div_g"), data, {
drawPoints: true,
showRoller: true,
valueRange: [0.0, 1.2],
labels: ['Time', 'Random']
});
// It sucks that these things aren't objects, and we need to store state in window.
window.intervalId = setInterval(function() {
var x = new Date(); // current time
var y = Math.random();
data.push([x, y]);
g.updateOptions({
'file': data
});
}, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<div id="div_g" style="width:600px; height:300px;"></div>
<p>This test is modeled after a
<a href="http://www.highcharts.com/demo/?example=dynamic-update&theme=default">highcharts
test</a>. New points should appear once per second. Try zooming and panning over to the right edge to watch them show up.</p>
这正是我需要的。
但是,我可以看到没有滚动选项(如果我错了,请纠正我)。因此,我的问题是如何模拟滚动功能,使旧图表点向左移动。
可以通过编程平移图表来完成吗?。或者通过其他更好的方式。
请推荐!!!!
【问题讨论】:
标签: javascript dygraphs