positioning.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Tooltip Interaction Modes</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(position) {
  32. return {
  33. type: 'line',
  34. data: {
  35. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  36. datasets: [{
  37. label: 'My First dataset',
  38. borderColor: window.chartColors.red,
  39. backgroundColor: window.chartColors.red,
  40. data: [10, 30, 46, 2, 8, 50, 0],
  41. fill: false,
  42. }, {
  43. label: 'My Second dataset',
  44. borderColor: window.chartColors.blue,
  45. backgroundColor: window.chartColors.blue,
  46. data: [7, 49, 46, 13, 25, 30, 22],
  47. fill: false,
  48. }]
  49. },
  50. options: {
  51. responsive: true,
  52. title: {
  53. display: true,
  54. text: 'Tooltip Position: ' + position
  55. },
  56. tooltips: {
  57. position: position,
  58. mode: 'index',
  59. intersect: false,
  60. },
  61. }
  62. };
  63. }
  64. window.onload = function() {
  65. var container = document.querySelector('.container');
  66. ['average', 'nearest'].forEach(function(position) {
  67. var div = document.createElement('div');
  68. div.classList.add('chart-container');
  69. var canvas = document.createElement('canvas');
  70. div.appendChild(canvas);
  71. container.appendChild(div);
  72. var ctx = canvas.getContext('2d');
  73. var config = createConfig(position);
  74. new Chart(ctx, config);
  75. });
  76. };
  77. </script>
  78. </body>
  79. </html>