Skip to content

Instantly share code, notes, and snippets.

@rossdylan
Created October 2, 2013 21:29
Show Gist options
  • Save rossdylan/6800797 to your computer and use it in GitHub Desktop.
Save rossdylan/6800797 to your computer and use it in GitHub Desktop.
scrolling barchart with chart.js
<!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>
@adamellsworth
Copy link

@ivanbylinkin thanks!

@adithyamaheshb
Copy link

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