morris.js/examples/updating.html

50 lines
1.3 KiB
HTML
Raw Normal View History

2012-06-10 19:30:51 +02:00
<!doctype html>
<head>
2014-02-02 20:27:55 +01:00
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
2012-06-10 19:30:51 +02:00
<script src="../morris.js"></script>
2014-02-02 21:28:13 +01:00
<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.min.js"></script>
2012-06-10 19:30:51 +02:00
<script src="lib/example.js"></script>
<link rel="stylesheet" href="lib/example.css">
2014-02-02 21:28:13 +01:00
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.min.css">
<link rel="stylesheet" href="../morris.css">
2012-06-10 19:30:51 +02:00
</head>
<body>
2012-06-10 20:48:12 +02:00
<h1>Updating data</h1>
2012-06-10 19:30:51 +02:00
<div id="graph"></div>
<div id="reloadStatus">
<pre id="code" class="prettyprint linenums">
2012-06-10 20:21:40 +02:00
2012-06-10 19:30:51 +02:00
var nReloads = 0;
2012-06-10 20:21:40 +02:00
function data(offset) {
var ret = [];
for (var x = 0; x <= 360; x += 10) {
var v = (offset + x) % 360;
ret.push({
x: x,
y: Math.sin(Math.PI * v / 180).toFixed(4),
z: Math.cos(Math.PI * v / 180).toFixed(4)
});
}
return ret;
}
2012-06-10 19:30:51 +02:00
var graph = Morris.Line({
element: 'graph',
2012-06-10 20:21:40 +02:00
data: data(0),
xkey: 'x',
ykeys: ['y', 'z'],
labels: ['sin()', 'cos()'],
2012-06-10 19:30:51 +02:00
parseTime: false,
2012-06-10 20:21:40 +02:00
ymin: -1.0,
ymax: 1.0,
hideHover: true
2012-06-10 19:30:51 +02:00
});
function update() {
nReloads++;
2012-06-10 20:21:40 +02:00
graph.setData(data(5 * nReloads));
2012-06-10 19:30:51 +02:00
$('#reloadStatus').text(nReloads + ' reloads');
}
2012-06-10 20:21:40 +02:00
setInterval(update, 100);
2012-06-10 19:30:51 +02:00
</pre>
</body>