2015-12-12 16:01:08 +01:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title> Animation Callbacks </title>
|
2016-02-12 07:45:25 +01:00
|
|
|
<script src="../../dist/Chart.bundle.js"></script>
|
2016-10-21 05:12:10 +02:00
|
|
|
<script src="../chartColors.js"></script>
|
2015-12-12 16:01:08 +01:00
|
|
|
<style>
|
2016-02-28 08:29:29 +01:00
|
|
|
canvas {
|
|
|
|
-moz-user-select: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
}
|
2015-12-12 16:01:08 +01:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2016-02-28 08:29:29 +01:00
|
|
|
<div style="width: 75%;">
|
|
|
|
<canvas id="canvas"></canvas>
|
2015-12-12 16:01:08 +01:00
|
|
|
<progress id="animationProgress" max="1" value="0" style="width: 100%"></progress>
|
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<button id="randomizeData">Randomize Data</button>
|
|
|
|
<script>
|
2016-02-28 08:29:29 +01:00
|
|
|
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
|
|
|
2015-12-12 16:01:08 +01:00
|
|
|
var randomScalingFactor = function() {
|
|
|
|
return Math.round(Math.random() * 100);
|
|
|
|
};
|
|
|
|
|
2016-10-21 05:12:10 +02:00
|
|
|
var progress = document.getElementById('animationProgress');
|
2015-12-12 16:01:08 +01:00
|
|
|
|
|
|
|
var config = {
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
|
|
|
datasets: [{
|
|
|
|
fill: false,
|
2016-10-21 05:12:10 +02:00
|
|
|
borderColor: window.chartColors.red,
|
|
|
|
backgroundColor: window.chartColors.red,
|
|
|
|
data: [
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor()
|
|
|
|
]
|
2015-12-12 16:01:08 +01:00
|
|
|
}, {
|
|
|
|
label: "My Second dataset ",
|
2016-10-21 05:12:10 +02:00
|
|
|
fill: false,
|
|
|
|
borderColor: window.chartColors.blue,
|
|
|
|
backgroundColor: window.chartColors.blue,
|
|
|
|
data: [
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor(),
|
|
|
|
randomScalingFactor()
|
|
|
|
]
|
2015-12-12 16:01:08 +01:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
2016-02-28 08:29:29 +01:00
|
|
|
title:{
|
|
|
|
display:true,
|
2016-10-21 05:12:10 +02:00
|
|
|
text: "Chart.js Line Chart - Animation Progress Bar"
|
2016-02-28 08:29:29 +01:00
|
|
|
},
|
2015-12-12 16:01:08 +01:00
|
|
|
animation: {
|
|
|
|
duration: 2000,
|
|
|
|
onProgress: function(animation) {
|
2016-10-21 05:12:10 +02:00
|
|
|
progress.value = animation.animationObject.currentStep / animation.animationObject.numSteps;
|
2015-12-12 16:01:08 +01:00
|
|
|
},
|
|
|
|
onComplete: function(animation) {
|
|
|
|
window.setTimeout(function() {
|
2016-10-21 05:12:10 +02:00
|
|
|
progress.value = 0;
|
2015-12-12 16:01:08 +01:00
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
var ctx = document.getElementById("canvas").getContext("2d");
|
|
|
|
window.myLine = new Chart(ctx, config);
|
|
|
|
};
|
|
|
|
|
2016-10-21 05:12:10 +02:00
|
|
|
document.getElementById('randomizeData').addEventListener('click', function() {
|
|
|
|
config.data.datasets.forEach(function(dataset) {
|
2015-12-12 16:01:08 +01:00
|
|
|
dataset.data = dataset.data.map(function() {
|
|
|
|
return randomScalingFactor();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
window.myLine.update();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|