scatter.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Scatter 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 color = Chart.helpers.color;
  21. var scatterChartData = {
  22. datasets: [{
  23. borderColor: window.chartColors.red,
  24. backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
  25. label: 'V(node2)',
  26. data: [{
  27. x: 1,
  28. y: -1.711e-2,
  29. }, {
  30. x: 1.26,
  31. y: -2.708e-2,
  32. }, {
  33. x: 1.58,
  34. y: -4.285e-2,
  35. }, {
  36. x: 2.0,
  37. y: -6.772e-2,
  38. }, {
  39. x: 2.51,
  40. y: -1.068e-1,
  41. }, {
  42. x: 3.16,
  43. y: -1.681e-1,
  44. }, {
  45. x: 3.98,
  46. y: -2.635e-1,
  47. }, {
  48. x: 5.01,
  49. y: -4.106e-1,
  50. }, {
  51. x: 6.31,
  52. y: -6.339e-1,
  53. }, {
  54. x: 7.94,
  55. y: -9.659e-1,
  56. }, {
  57. x: 10.00,
  58. y: -1.445,
  59. }, {
  60. x: 12.6,
  61. y: -2.110,
  62. }, {
  63. x: 15.8,
  64. y: -2.992,
  65. }, {
  66. x: 20.0,
  67. y: -4.102,
  68. }, {
  69. x: 25.1,
  70. y: -5.429,
  71. }, {
  72. x: 31.6,
  73. y: -6.944,
  74. }, {
  75. x: 39.8,
  76. y: -8.607,
  77. }, {
  78. x: 50.1,
  79. y: -1.038e1,
  80. }, {
  81. x: 63.1,
  82. y: -1.223e1,
  83. }, {
  84. x: 79.4,
  85. y: -1.413e1,
  86. }, {
  87. x: 100.00,
  88. y: -1.607e1,
  89. }, {
  90. x: 126,
  91. y: -1.803e1,
  92. }, {
  93. x: 158,
  94. y: -2e1,
  95. }, {
  96. x: 200,
  97. y: -2.199e1,
  98. }, {
  99. x: 251,
  100. y: -2.398e1,
  101. }, {
  102. x: 316,
  103. y: -2.597e1,
  104. }, {
  105. x: 398,
  106. y: -2.797e1,
  107. }, {
  108. x: 501,
  109. y: -2.996e1,
  110. }, {
  111. x: 631,
  112. y: -3.196e1,
  113. }, {
  114. x: 794,
  115. y: -3.396e1,
  116. }, {
  117. x: 1000,
  118. y: -3.596e1,
  119. }]
  120. }]
  121. };
  122. window.onload = function() {
  123. var ctx = document.getElementById('canvas').getContext('2d');
  124. window.myScatter = Chart.Scatter(ctx, {
  125. data: scatterChartData,
  126. options: {
  127. title: {
  128. display: true,
  129. text: 'Chart.js Scatter Chart - Logarithmic X-Axis'
  130. },
  131. scales: {
  132. xAxes: [{
  133. type: 'logarithmic',
  134. position: 'bottom',
  135. ticks: {
  136. userCallback: function(tick) {
  137. var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
  138. if (remain === 1 || remain === 2 || remain === 5) {
  139. return tick.toString() + 'Hz';
  140. }
  141. return '';
  142. },
  143. },
  144. scaleLabel: {
  145. labelString: 'Frequency',
  146. display: true,
  147. }
  148. }],
  149. yAxes: [{
  150. type: 'linear',
  151. ticks: {
  152. userCallback: function(tick) {
  153. return tick.toString() + 'dB';
  154. }
  155. },
  156. scaleLabel: {
  157. labelString: 'Voltage',
  158. display: true
  159. }
  160. }]
  161. }
  162. }
  163. });
  164. };
  165. </script>
  166. </body>
  167. </html>