logarithmic-line.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>Chart with Logarithmic Scale</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #chart {
  11. max-width: 650px;
  12. margin: 35px auto;
  13. }
  14. </style>
  15. <script>
  16. window.Promise ||
  17. document.write(
  18. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  19. )
  20. window.Promise ||
  21. document.write(
  22. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  23. )
  24. window.Promise ||
  25. document.write(
  26. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  27. )
  28. </script>
  29. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  30. <script>
  31. var data = [{
  32. x: 1994,
  33. y: 2543763
  34. },
  35. {
  36. x: 1995,
  37. y: 4486659
  38. },
  39. {
  40. x: 1996,
  41. y: 7758386
  42. },
  43. {
  44. x: 1997,
  45. y: 12099221
  46. },
  47. {
  48. x: 1998,
  49. y: 18850762
  50. },
  51. {
  52. x: 1999,
  53. y: 28153765
  54. },
  55. {
  56. x: 2000,
  57. y: 41479495
  58. },
  59. {
  60. x: 2001,
  61. y: 50229224
  62. },
  63. {
  64. x: 2002,
  65. y: 66506501
  66. },
  67. {
  68. x: 2003,
  69. y: 78143598
  70. },
  71. {
  72. x: 2004,
  73. y: 91332777
  74. },
  75. {
  76. x: 2005,
  77. y: 103010128
  78. },
  79. {
  80. x: 2006,
  81. y: 116291681
  82. },
  83. {
  84. x: 2007,
  85. y: 137322698
  86. },
  87. {
  88. x: 2008,
  89. y: 157506752
  90. },
  91. {
  92. x: 2009,
  93. y: 176640381
  94. },
  95. {
  96. x: 2010,
  97. y: 202320297
  98. },
  99. {
  100. x: 2011,
  101. y: 223195735
  102. },
  103. {
  104. x: 2012,
  105. y: 249473624
  106. },
  107. {
  108. x: 2013,
  109. y: 272842810
  110. },
  111. {
  112. x: 2014,
  113. y: 295638556
  114. },
  115. {
  116. x: 2015,
  117. y: 318599615
  118. },
  119. {
  120. x: 2016,
  121. y: 342497123
  122. }
  123. ]
  124. var labelFormatter = function (value) {
  125. var val = Math.abs(value)
  126. if (val >= 1000000) {
  127. val = (val / 1000000).toFixed(1) + ' M';
  128. }
  129. return val;
  130. }
  131. </script>
  132. </head>
  133. <body>
  134. <div id="chart"></div>
  135. <script>
  136. var options = {
  137. series: [{
  138. name: "Logarithmic",
  139. data: data
  140. }, {
  141. name: "Linear",
  142. data: data
  143. }],
  144. chart: {
  145. height: 350,
  146. type: 'line',
  147. zoom: {
  148. enabled: false
  149. }
  150. },
  151. dataLabels: {
  152. enabled: false
  153. },
  154. stroke: {
  155. curve: 'straight'
  156. },
  157. title: {
  158. text: 'Logarithmic Scale',
  159. align: 'left'
  160. },
  161. xaxis: {
  162. type: 'datetime'
  163. },
  164. yaxis: [
  165. {
  166. min: 1000000,
  167. max: 500000000,
  168. tickAmount: 4,
  169. logarithmic: true,
  170. seriesName: 'Logarithmic',
  171. labels: {
  172. formatter: labelFormatter,
  173. style: {
  174. fontWeight: 900,
  175. colors: 'rgb(0, 143, 251)'
  176. }
  177. },
  178. title: {
  179. text: 'Logarithmic',
  180. style: {
  181. fontWeight: 900,
  182. color: 'rgb(0, 143, 251)'
  183. }
  184. }
  185. },
  186. {
  187. min: 1000000,
  188. max: 500000000,
  189. opposite: true,
  190. tickAmount: 4,
  191. seriesName: 'Linear',
  192. labels: {
  193. formatter: labelFormatter,
  194. style: {
  195. fontWeight: 900,
  196. colors: 'rgb(0, 227, 150)'
  197. }
  198. },
  199. title: {
  200. text: 'Linear',
  201. style: {
  202. fontWeight: 900,
  203. color: 'rgb(0, 227, 150)'
  204. }
  205. }
  206. }
  207. ]
  208. };
  209. var chart = new ApexCharts(document.querySelector("#chart"), options);
  210. chart.render();
  211. </script>
  212. </body>
  213. </html>