basic.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Scatter 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 color = Chart.helpers.color;
  22. var scatterChartData = {
  23. datasets: [{
  24. label: 'My First dataset',
  25. borderColor: window.chartColors.red,
  26. backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
  27. data: [{
  28. x: randomScalingFactor(),
  29. y: randomScalingFactor(),
  30. }, {
  31. x: randomScalingFactor(),
  32. y: randomScalingFactor(),
  33. }, {
  34. x: randomScalingFactor(),
  35. y: randomScalingFactor(),
  36. }, {
  37. x: randomScalingFactor(),
  38. y: randomScalingFactor(),
  39. }, {
  40. x: randomScalingFactor(),
  41. y: randomScalingFactor(),
  42. }, {
  43. x: randomScalingFactor(),
  44. y: randomScalingFactor(),
  45. }, {
  46. x: randomScalingFactor(),
  47. y: randomScalingFactor(),
  48. }]
  49. }, {
  50. label: 'My Second dataset',
  51. borderColor: window.chartColors.blue,
  52. backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
  53. data: [{
  54. x: randomScalingFactor(),
  55. y: randomScalingFactor(),
  56. }, {
  57. x: randomScalingFactor(),
  58. y: randomScalingFactor(),
  59. }, {
  60. x: randomScalingFactor(),
  61. y: randomScalingFactor(),
  62. }, {
  63. x: randomScalingFactor(),
  64. y: randomScalingFactor(),
  65. }, {
  66. x: randomScalingFactor(),
  67. y: randomScalingFactor(),
  68. }, {
  69. x: randomScalingFactor(),
  70. y: randomScalingFactor(),
  71. }, {
  72. x: randomScalingFactor(),
  73. y: randomScalingFactor(),
  74. }]
  75. }]
  76. };
  77. window.onload = function() {
  78. var ctx = document.getElementById('canvas').getContext('2d');
  79. window.myScatter = Chart.Scatter(ctx, {
  80. data: scatterChartData,
  81. options: {
  82. title: {
  83. display: true,
  84. text: 'Chart.js Scatter Chart'
  85. },
  86. }
  87. });
  88. };
  89. document.getElementById('randomizeData').addEventListener('click', function() {
  90. scatterChartData.datasets.forEach(function(dataset) {
  91. dataset.data = dataset.data.map(function() {
  92. return {
  93. x: randomScalingFactor(),
  94. y: randomScalingFactor()
  95. };
  96. });
  97. });
  98. window.myScatter.update();
  99. });
  100. </script>
  101. </body>
  102. </html>