stepped.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Stepped 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. .chart-container {
  14. width: 500px;
  15. margin-left: 40px;
  16. margin-right: 40px;
  17. margin-bottom: 40px;
  18. }
  19. .container {
  20. display: flex;
  21. flex-direction: row;
  22. flex-wrap: wrap;
  23. justify-content: center;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="container">
  29. </div>
  30. <script>
  31. function createConfig(details, data) {
  32. return {
  33. type: 'line',
  34. data: {
  35. labels: ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6'],
  36. datasets: [{
  37. label: 'steppedLine: ' + details.steppedLine,
  38. steppedLine: details.steppedLine,
  39. data: data,
  40. borderColor: details.color,
  41. fill: false,
  42. }]
  43. },
  44. options: {
  45. responsive: true,
  46. title: {
  47. display: true,
  48. text: details.label,
  49. }
  50. }
  51. };
  52. }
  53. window.onload = function() {
  54. var container = document.querySelector('.container');
  55. var data = [
  56. randomScalingFactor(),
  57. randomScalingFactor(),
  58. randomScalingFactor(),
  59. randomScalingFactor(),
  60. randomScalingFactor(),
  61. randomScalingFactor()
  62. ];
  63. var steppedLineSettings = [{
  64. steppedLine: false,
  65. label: 'No Step Interpolation',
  66. color: window.chartColors.red
  67. }, {
  68. steppedLine: true,
  69. label: 'Step Before Interpolation',
  70. color: window.chartColors.green
  71. }, {
  72. steppedLine: 'before',
  73. label: 'Step Before Interpolation',
  74. color: window.chartColors.green
  75. }, {
  76. steppedLine: 'after',
  77. label: 'Step After Interpolation',
  78. color: window.chartColors.purple
  79. }];
  80. steppedLineSettings.forEach(function(details) {
  81. var div = document.createElement('div');
  82. div.classList.add('chart-container');
  83. var canvas = document.createElement('canvas');
  84. div.appendChild(canvas);
  85. container.appendChild(div);
  86. var ctx = canvas.getContext('2d');
  87. var config = createConfig(details, data);
  88. new Chart(ctx, config);
  89. });
  90. };
  91. </script>
  92. </body>
  93. </html>