line.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Logarithmic 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 randomScalingFactor = function() {
  22. return Math.ceil(Math.random() * 10.0) * Math.pow(10, Math.ceil(Math.random() * 5));
  23. };
  24. var config = {
  25. type: 'line',
  26. data: {
  27. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  28. datasets: [{
  29. label: 'My First dataset',
  30. backgroundColor: window.chartColors.red,
  31. borderColor: window.chartColors.red,
  32. fill: false,
  33. data: [
  34. randomScalingFactor(),
  35. randomScalingFactor(),
  36. randomScalingFactor(),
  37. randomScalingFactor(),
  38. randomScalingFactor(),
  39. randomScalingFactor(),
  40. randomScalingFactor()
  41. ],
  42. }, {
  43. label: 'My Second dataset',
  44. backgroundColor: window.chartColors.blue,
  45. borderColor: window.chartColors.blue,
  46. fill: false,
  47. data: [
  48. randomScalingFactor(),
  49. randomScalingFactor(),
  50. randomScalingFactor(),
  51. randomScalingFactor(),
  52. randomScalingFactor(),
  53. randomScalingFactor(),
  54. randomScalingFactor()
  55. ],
  56. }]
  57. },
  58. options: {
  59. responsive: true,
  60. title: {
  61. display: true,
  62. text: 'Chart.js Line Chart - Logarithmic'
  63. },
  64. scales: {
  65. xAxes: [{
  66. display: true,
  67. }],
  68. yAxes: [{
  69. display: true,
  70. type: 'logarithmic',
  71. }]
  72. }
  73. }
  74. };
  75. window.onload = function() {
  76. var ctx = document.getElementById('canvas').getContext('2d');
  77. window.myLine = new Chart(ctx, config);
  78. };
  79. document.getElementById('randomizeData').addEventListener('click', function() {
  80. config.data.datasets.forEach(function(dataset) {
  81. dataset.data = dataset.data.map(function() {
  82. return randomScalingFactor();
  83. });
  84. });
  85. window.myLine.update();
  86. });
  87. </script>
  88. </body>
  89. </html>