skip-points.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>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. <script>
  20. var config = {
  21. type: 'line',
  22. data: {
  23. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  24. datasets: [{
  25. label: 'My First dataset',
  26. borderColor: window.chartColors.red,
  27. fill: false,
  28. // Skip a point in the middle
  29. data: [
  30. randomScalingFactor(),
  31. randomScalingFactor(),
  32. NaN,
  33. randomScalingFactor(),
  34. randomScalingFactor(),
  35. randomScalingFactor(),
  36. randomScalingFactor()
  37. ],
  38. }, {
  39. label: 'My Second dataset',
  40. borderColor: window.chartColors.blue,
  41. fill: false,
  42. // Skip first and last points
  43. data: [
  44. NaN,
  45. randomScalingFactor(),
  46. randomScalingFactor(),
  47. randomScalingFactor(),
  48. randomScalingFactor(),
  49. randomScalingFactor(),
  50. NaN
  51. ],
  52. }]
  53. },
  54. options: {
  55. responsive: true,
  56. title: {
  57. display: true,
  58. text: 'Chart.js Line Chart - Skip Points'
  59. },
  60. tooltips: {
  61. mode: 'index',
  62. },
  63. hover: {
  64. mode: 'index'
  65. },
  66. scales: {
  67. xAxes: [{
  68. display: true,
  69. scaleLabel: {
  70. display: true,
  71. labelString: 'Month'
  72. }
  73. }],
  74. yAxes: [{
  75. display: true,
  76. scaleLabel: {
  77. display: true,
  78. labelString: 'Value'
  79. },
  80. }]
  81. }
  82. }
  83. };
  84. window.onload = function() {
  85. var ctx = document.getElementById('canvas').getContext('2d');
  86. window.myLine = new Chart(ctx, config);
  87. };
  88. </script>
  89. </body>
  90. </html>