2013-03-18 00:57:50 +01:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
2015-05-12 09:13:16 +02:00
|
|
|
<head>
|
|
|
|
<title>Bar Chart</title>
|
|
|
|
<script src="../Chart.js"></script>
|
|
|
|
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<div style="width: 100%">
|
|
|
|
<canvas id="canvas" height="450" width="600"></canvas>
|
|
|
|
</div>
|
|
|
|
<button id="randomizeData">Randomize Data</button>
|
|
|
|
<script>
|
2015-05-12 14:00:14 +02:00
|
|
|
var randomScalingFactor = function(){
|
|
|
|
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random()*100)
|
2015-05-12 09:13:16 +02:00
|
|
|
};
|
|
|
|
var randomColorFactor = function() {
|
|
|
|
return Math.round(Math.random() * 255)
|
|
|
|
};
|
|
|
|
|
|
|
|
var barChartData = {
|
|
|
|
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
|
|
|
datasets: [{
|
2015-05-12 20:55:48 +02:00
|
|
|
label: 'Dataset 1',
|
2015-05-12 09:13:16 +02:00
|
|
|
backgroundColor: "rgba(220,220,220,0.5)",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
|
|
}, {
|
2015-05-12 20:55:48 +02:00
|
|
|
label: 'Dataset 2',
|
2015-05-12 09:13:16 +02:00
|
|
|
backgroundColor: "rgba(151,187,205,0.5)",
|
|
|
|
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
|
|
|
}]
|
|
|
|
|
|
|
|
}
|
|
|
|
window.onload = function() {
|
|
|
|
var ctx = document.getElementById("canvas").getContext("2d");
|
|
|
|
window.myBar = new Chart(ctx).Bar(barChartData, {
|
|
|
|
responsive: true,
|
2015-05-13 01:22:47 +02:00
|
|
|
hoverMode: 'label',
|
2015-05-12 14:00:14 +02:00
|
|
|
scaleBeginAtZero: false,
|
2015-05-15 07:18:47 +02:00
|
|
|
hoverAnimationDuration: 400
|
2015-05-12 09:13:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#randomizeData').click(function() {
|
|
|
|
barChartData.datasets[0].backgroundColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
|
|
|
barChartData.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
|
|
|
|
|
|
|
|
barChartData.datasets[1].backgroundColor = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
|
|
|
|
barChartData.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
|
|
|
|
|
|
|
|
window.myBar.update();
|
2015-01-08 18:13:14 +01:00
|
|
|
});
|
2015-05-12 09:13:16 +02:00
|
|
|
</script>
|
|
|
|
</body>
|
2013-03-18 00:57:50 +01:00
|
|
|
</html>
|