point-styles.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. .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(pointStyle) {
  32. return {
  33. type: 'line',
  34. data: {
  35. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  36. datasets: [{
  37. label: 'My First dataset',
  38. backgroundColor: window.chartColors.red,
  39. borderColor: window.chartColors.red,
  40. data: [10, 23, 5, 99, 67, 43, 0],
  41. fill: false,
  42. pointRadius: 10,
  43. pointHoverRadius: 15,
  44. showLine: false // no line shown
  45. }]
  46. },
  47. options: {
  48. responsive: true,
  49. title: {
  50. display: true,
  51. text: 'Point Style: ' + pointStyle
  52. },
  53. legend: {
  54. display: false
  55. },
  56. elements: {
  57. point: {
  58. pointStyle: pointStyle
  59. }
  60. }
  61. }
  62. };
  63. }
  64. window.onload = function() {
  65. var container = document.querySelector('.container');
  66. [
  67. 'circle',
  68. 'triangle',
  69. 'rect',
  70. 'rectRounded',
  71. 'rectRot',
  72. 'cross',
  73. 'crossRot',
  74. 'star',
  75. 'line',
  76. 'dash'
  77. ].forEach(function(pointStyle) {
  78. var div = document.createElement('div');
  79. div.classList.add('chart-container');
  80. var canvas = document.createElement('canvas');
  81. div.appendChild(canvas);
  82. container.appendChild(div);
  83. var ctx = canvas.getContext('2d');
  84. var config = createConfig(pointStyle);
  85. new Chart(ctx, config);
  86. });
  87. };
  88. </script>
  89. </body>
  90. </html>