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 hidden or 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure if anyone is still using this or if OP is still updating this, but using the above method will create a funky chart overlay every time you hover over any bar in the chart. If you modify it just a little bit to destroy the chart before creating a new one it will function exactly the same but you won't have any problems with hovering. If you take a little longer on it you can even use the update() method for a faster/cleaner implementation. Nevertheless the adding the destroy function would be an improvement: