Created
October 2, 2013 21:29
-
-
Save rossdylan/6800797 to your computer and use it in GitHub Desktop.
scrolling barchart with chart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="Chart.js"></script> | |
</head> | |
<body> | |
<canvas id="canvas" height="450" width="1000"></canvas> | |
<script> | |
var data = { | |
labels: ["","","","","","","","","","","","","","","","","","","",""], | |
datasets: [ | |
{ | |
data: [10,15,5,10,12,6,19,10,5,7] | |
} | |
] | |
} | |
options = { | |
animation: false, | |
barValueSpacing: 1 | |
} | |
var chart = new Chart(document.getElementById("canvas").getContext("2d")); | |
chart.Bar(data, options); | |
function getRandomInt(min,max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
setInterval(function () { | |
data.datasets[0].data.unshift(getRandomInt(0,20)); | |
if(data.datasets[0].data.length >= 21) { | |
data.datasets[0].data.pop(); | |
} | |
chart.Bar(data, options); | |
}, 1000); | |
</script> | |
</body> | |
</html> |
What version of chart.js are you guys using?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ivanbylinkin thanks!