Advertisement
Guest User

Untitled

a guest
May 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.  
  4. <head>
  5. <title>Scatter Chart</title>
  6. <script src="../node_modules/chart.js/dist/Chart.bundle.js"></script>
  7. <script src="../node_modules/hammerjs/hammer.min.js"></script>
  8. <script src="../Chart.Zoom.js"></script>
  9. <style>
  10. canvas {
  11. -moz-user-select: none;
  12. -webkit-user-select: none;
  13. -ms-user-select: none;
  14. }
  15. </style>
  16. </head>
  17.  
  18. <body>
  19. <div style="width:100%">
  20. <div>
  21. <canvas id="canvas"></canvas>
  22. </div>
  23. </div>
  24. <script>
  25. var randomColor = function(opacity) {
  26. return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
  27. };
  28.  
  29. var scatterChartData = {
  30. datasets: [{
  31. label: "My only dataset",
  32. data: [{
  33. x: 0,
  34. y: 0,
  35. }, {
  36. x: 20,
  37. y: 20,
  38. }, {
  39. x: 40,
  40. y: 0,
  41. }],
  42. lineTension: 0,
  43. }]
  44. };
  45.  
  46. scatterChartData.datasets.forEach(function(dataset) {
  47. dataset.borderColor = randomColor(0.4);
  48. dataset.backgroundColor = randomColor(0.1);
  49. dataset.pointBorderColor = randomColor(0.7);
  50. dataset.pointBackgroundColor = randomColor(0.5);
  51. dataset.pointBorderWidth = 1;
  52. });
  53.  
  54. window.onload = function() {
  55. var ctx = document.getElementById("canvas").getContext("2d");
  56. window.myScatter = Chart.Scatter(ctx, {
  57. data: scatterChartData,
  58. options: {
  59. title: {
  60. display: true,
  61. text: 'Chart.js Scatter Chart'
  62. },
  63. scales: {
  64. xAxes: [{
  65. position: 'top',
  66. gridLines: {
  67. zeroLineColor: "rgba(0,255,0,1)"
  68. },
  69. scaleLabel: {
  70. display: true,
  71. labelString: 'x axis'
  72. },
  73. ticks: {
  74. maxRotation: 0,
  75. reverse: true
  76. }
  77. }],
  78. yAxes: [{
  79. position: 'right',
  80. gridLines: {
  81. zeroLineColor: "rgba(0,255,0,1)"
  82. },
  83. scaleLabel: {
  84. display: true,
  85. labelString: 'y axis'
  86. },
  87. ticks: {
  88. reverse: true
  89. }
  90. }]
  91. },
  92. pan: {
  93. enabled: true,
  94. mode: 'xy',
  95. threshold: 10,
  96. },
  97. zoom: {
  98. enabled: true,
  99. mode: 'xy',
  100. limits: {
  101. max: 10,
  102. min: 0.5
  103. }
  104. }
  105. }
  106. });
  107. };
  108. </script>
  109. </body>
  110.  
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement