progress-bar.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title> Animation Callbacks </title>
  5. <script src="../../dist/Chart.bundle.js"></script>
  6. <script src="../utils.js"></script>
  7. <style>
  8. canvas {
  9. -moz-user-select: none;
  10. -webkit-user-select: none;
  11. -ms-user-select: none;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div style="width: 75%;">
  17. <canvas id="canvas"></canvas>
  18. <progress id="animationProgress" max="1" value="0" style="width: 100%"></progress>
  19. </div>
  20. <br>
  21. <br>
  22. <button id="randomizeData">Randomize Data</button>
  23. <script>
  24. var progress = document.getElementById('animationProgress');
  25. var config = {
  26. type: 'line',
  27. data: {
  28. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  29. datasets: [{
  30. fill: false,
  31. borderColor: window.chartColors.red,
  32. backgroundColor: window.chartColors.red,
  33. data: [
  34. randomScalingFactor(),
  35. randomScalingFactor(),
  36. randomScalingFactor(),
  37. randomScalingFactor(),
  38. randomScalingFactor(),
  39. randomScalingFactor(),
  40. randomScalingFactor()
  41. ]
  42. }, {
  43. label: 'My Second dataset ',
  44. fill: false,
  45. borderColor: window.chartColors.blue,
  46. backgroundColor: window.chartColors.blue,
  47. data: [
  48. randomScalingFactor(),
  49. randomScalingFactor(),
  50. randomScalingFactor(),
  51. randomScalingFactor(),
  52. randomScalingFactor(),
  53. randomScalingFactor(),
  54. randomScalingFactor()
  55. ]
  56. }]
  57. },
  58. options: {
  59. title: {
  60. display: true,
  61. text: 'Chart.js Line Chart - Animation Progress Bar'
  62. },
  63. animation: {
  64. duration: 2000,
  65. onProgress: function(animation) {
  66. progress.value = animation.currentStep / animation.numSteps;
  67. },
  68. onComplete: function() {
  69. window.setTimeout(function() {
  70. progress.value = 0;
  71. }, 2000);
  72. }
  73. }
  74. }
  75. };
  76. window.onload = function() {
  77. var ctx = document.getElementById('canvas').getContext('2d');
  78. window.myLine = new Chart(ctx, config);
  79. };
  80. document.getElementById('randomizeData').addEventListener('click', function() {
  81. config.data.datasets.forEach(function(dataset) {
  82. dataset.data = dataset.data.map(function() {
  83. return randomScalingFactor();
  84. });
  85. });
  86. window.myLine.update();
  87. });
  88. </script>
  89. </body>
  90. </html>