gridlines-display.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Grid Lines Display Settings</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"></div>
  29. <script>
  30. function createConfig(gridlines, title) {
  31. return {
  32. type: 'line',
  33. data: {
  34. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  35. datasets: [{
  36. label: 'My First dataset',
  37. backgroundColor: window.chartColors.red,
  38. borderColor: window.chartColors.red,
  39. data: [10, 30, 39, 20, 25, 34, 0],
  40. fill: false,
  41. }, {
  42. label: 'My Second dataset',
  43. fill: false,
  44. backgroundColor: window.chartColors.blue,
  45. borderColor: window.chartColors.blue,
  46. data: [18, 33, 22, 19, 11, 39, 30],
  47. }]
  48. },
  49. options: {
  50. responsive: true,
  51. title: {
  52. display: true,
  53. text: title
  54. },
  55. scales: {
  56. xAxes: [{
  57. gridLines: gridlines
  58. }],
  59. yAxes: [{
  60. gridLines: gridlines,
  61. ticks: {
  62. min: 0,
  63. max: 100,
  64. stepSize: 10
  65. }
  66. }]
  67. }
  68. }
  69. };
  70. }
  71. window.onload = function() {
  72. var container = document.querySelector('.container');
  73. [{
  74. title: 'Display: true',
  75. gridLines: {
  76. display: true
  77. }
  78. }, {
  79. title: 'Display: false',
  80. gridLines: {
  81. display: false
  82. }
  83. }, {
  84. title: 'Display: false, no border',
  85. gridLines: {
  86. display: false,
  87. drawBorder: false
  88. }
  89. }, {
  90. title: 'DrawOnChartArea: false',
  91. gridLines: {
  92. display: true,
  93. drawBorder: true,
  94. drawOnChartArea: false,
  95. }
  96. }, {
  97. title: 'DrawTicks: false',
  98. gridLines: {
  99. display: true,
  100. drawBorder: true,
  101. drawOnChartArea: true,
  102. drawTicks: false,
  103. }
  104. }].forEach(function(details) {
  105. var div = document.createElement('div');
  106. div.classList.add('chart-container');
  107. var canvas = document.createElement('canvas');
  108. div.appendChild(canvas);
  109. container.appendChild(div);
  110. var ctx = canvas.getContext('2d');
  111. var config = createConfig(details.gridLines, details.title);
  112. new Chart(ctx, config);
  113. });
  114. };
  115. </script>
  116. </body>
  117. </html>