logarithmic-line.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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/react@16.12/umd/react.production.min.js"></script>
  30. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  31. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  32. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  33. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  34. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  35. <script>
  36. var data = [{
  37. x: 1994,
  38. y: 2543763
  39. },
  40. {
  41. x: 1995,
  42. y: 4486659
  43. },
  44. {
  45. x: 1996,
  46. y: 7758386
  47. },
  48. {
  49. x: 1997,
  50. y: 12099221
  51. },
  52. {
  53. x: 1998,
  54. y: 18850762
  55. },
  56. {
  57. x: 1999,
  58. y: 28153765
  59. },
  60. {
  61. x: 2000,
  62. y: 41479495
  63. },
  64. {
  65. x: 2001,
  66. y: 50229224
  67. },
  68. {
  69. x: 2002,
  70. y: 66506501
  71. },
  72. {
  73. x: 2003,
  74. y: 78143598
  75. },
  76. {
  77. x: 2004,
  78. y: 91332777
  79. },
  80. {
  81. x: 2005,
  82. y: 103010128
  83. },
  84. {
  85. x: 2006,
  86. y: 116291681
  87. },
  88. {
  89. x: 2007,
  90. y: 137322698
  91. },
  92. {
  93. x: 2008,
  94. y: 157506752
  95. },
  96. {
  97. x: 2009,
  98. y: 176640381
  99. },
  100. {
  101. x: 2010,
  102. y: 202320297
  103. },
  104. {
  105. x: 2011,
  106. y: 223195735
  107. },
  108. {
  109. x: 2012,
  110. y: 249473624
  111. },
  112. {
  113. x: 2013,
  114. y: 272842810
  115. },
  116. {
  117. x: 2014,
  118. y: 295638556
  119. },
  120. {
  121. x: 2015,
  122. y: 318599615
  123. },
  124. {
  125. x: 2016,
  126. y: 342497123
  127. }
  128. ]
  129. var labelFormatter = function (value) {
  130. var val = Math.abs(value)
  131. if (val >= 1000000) {
  132. val = (val / 1000000).toFixed(1) + ' M';
  133. }
  134. return val;
  135. }
  136. </script>
  137. </head>
  138. <body>
  139. <div id="app"></div>
  140. <div id="html">
  141. &lt;div id=&quot;chart&quot;&gt;
  142. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;line&quot; height={350} /&gt;
  143. &lt;/div&gt;
  144. </div>
  145. <script type="text/babel">
  146. class ApexChart extends React.Component {
  147. constructor(props) {
  148. super(props);
  149. this.state = {
  150. series: [{
  151. name: "Logarithmic",
  152. data: data
  153. }, {
  154. name: "Linear",
  155. data: data
  156. }],
  157. options: {
  158. chart: {
  159. height: 350,
  160. type: 'line',
  161. zoom: {
  162. enabled: false
  163. }
  164. },
  165. dataLabels: {
  166. enabled: false
  167. },
  168. stroke: {
  169. curve: 'straight'
  170. },
  171. title: {
  172. text: 'Logarithmic Scale',
  173. align: 'left'
  174. },
  175. xaxis: {
  176. type: 'datetime'
  177. },
  178. yaxis: [
  179. {
  180. min: 1000000,
  181. max: 500000000,
  182. tickAmount: 4,
  183. logarithmic: true,
  184. seriesName: 'Logarithmic',
  185. labels: {
  186. formatter: labelFormatter,
  187. style: {
  188. fontWeight: 900,
  189. colors: 'rgb(0, 143, 251)'
  190. }
  191. },
  192. title: {
  193. text: 'Logarithmic',
  194. style: {
  195. fontWeight: 900,
  196. color: 'rgb(0, 143, 251)'
  197. }
  198. }
  199. },
  200. {
  201. min: 1000000,
  202. max: 500000000,
  203. opposite: true,
  204. tickAmount: 4,
  205. seriesName: 'Linear',
  206. labels: {
  207. formatter: labelFormatter,
  208. style: {
  209. fontWeight: 900,
  210. colors: 'rgb(0, 227, 150)'
  211. }
  212. },
  213. title: {
  214. text: 'Linear',
  215. style: {
  216. fontWeight: 900,
  217. color: 'rgb(0, 227, 150)'
  218. }
  219. }
  220. }
  221. ]
  222. },
  223. };
  224. }
  225. render() {
  226. return (
  227. <div>
  228. <div id="chart">
  229. <ReactApexChart options={this.state.options} series={this.state.series} type="line" height={350} />
  230. </div>
  231. <div id="html-dist"></div>
  232. </div>
  233. );
  234. }
  235. }
  236. const domContainer = document.querySelector('#app');
  237. ReactDOM.render(React.createElement(ApexChart), domContainer);
  238. </script>
  239. </body>
  240. </html>