combo-bar-line.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Combo Bar-Line Chart</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. </div>
  19. <button id="randomizeData">Randomize Data</button>
  20. <script>
  21. var chartData = {
  22. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  23. datasets: [{
  24. type: 'line',
  25. label: 'Dataset 1',
  26. borderColor: window.chartColors.blue,
  27. borderWidth: 2,
  28. fill: false,
  29. data: [
  30. randomScalingFactor(),
  31. randomScalingFactor(),
  32. randomScalingFactor(),
  33. randomScalingFactor(),
  34. randomScalingFactor(),
  35. randomScalingFactor(),
  36. randomScalingFactor()
  37. ]
  38. }, {
  39. type: 'bar',
  40. label: 'Dataset 2',
  41. backgroundColor: window.chartColors.red,
  42. data: [
  43. randomScalingFactor(),
  44. randomScalingFactor(),
  45. randomScalingFactor(),
  46. randomScalingFactor(),
  47. randomScalingFactor(),
  48. randomScalingFactor(),
  49. randomScalingFactor()
  50. ],
  51. borderColor: 'white',
  52. borderWidth: 2
  53. }, {
  54. type: 'bar',
  55. label: 'Dataset 3',
  56. backgroundColor: window.chartColors.green,
  57. data: [
  58. randomScalingFactor(),
  59. randomScalingFactor(),
  60. randomScalingFactor(),
  61. randomScalingFactor(),
  62. randomScalingFactor(),
  63. randomScalingFactor(),
  64. randomScalingFactor()
  65. ]
  66. }]
  67. };
  68. window.onload = function() {
  69. var ctx = document.getElementById('canvas').getContext('2d');
  70. window.myMixedChart = new Chart(ctx, {
  71. type: 'bar',
  72. data: chartData,
  73. options: {
  74. responsive: true,
  75. title: {
  76. display: true,
  77. text: 'Chart.js Combo Bar Line Chart'
  78. },
  79. tooltips: {
  80. mode: 'index',
  81. intersect: true
  82. }
  83. }
  84. });
  85. };
  86. document.getElementById('randomizeData').addEventListener('click', function() {
  87. chartData.datasets.forEach(function(dataset) {
  88. dataset.data = dataset.data.map(function() {
  89. return randomScalingFactor();
  90. });
  91. });
  92. window.myMixedChart.update();
  93. });
  94. </script>
  95. </body>
  96. </html>