Skip to content

Instantly share code, notes, and snippets.

@davidjpfeiffer
Last active July 25, 2016 22:13
Show Gist options
  • Save davidjpfeiffer/a25d338967cb3bbc1a970b6a79f975d3 to your computer and use it in GitHub Desktop.
Save davidjpfeiffer/a25d338967cb3bbc1a970b6a79f975d3 to your computer and use it in GitHub Desktop.
This HTML file can be used with Chart JS to create a fully-functional example of the chart.
<!doctype html>
<html>
<head>
<title>Chart Example</title>
<script src="chart.js"></script>
</head>
<body>
<div style="width: 50%">
<canvas id="canvas" height="450" width="600"></canvas>
</div>
<script>
var getRandomDataArray = function () {
var dataArray = [];
for (var i = 0; i < 7; i++) dataArray.push(Math.round(Math.random() * 100));
return dataArray;
}
var chartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "#ffa500",
strokeColor : "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data : getRandomDataArray()
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,0.8)",
highlightFill : "rgba(151,187,205,0.75)",
highlightStroke : "rgba(151,187,205,1)",
data : getRandomDataArray()
}
]
}
window.onload = function(){
var chartOptions = { responsive : true };
var chart = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(chart).Bar(chartData, chartOptions);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment