multiple-yaxes.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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>Multiple Y Axis Chart</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #chart {
  11. max-width: 650px;
  12. margin: 35px auto;
  13. }
  14. .apexcharts-tooltip-title {
  15. display: none;
  16. }
  17. #chart .apexcharts-tooltip {
  18. display: flex;
  19. border: 0;
  20. box-shadow: none;
  21. }
  22. </style>
  23. <script>
  24. window.Promise ||
  25. document.write(
  26. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  27. )
  28. window.Promise ||
  29. document.write(
  30. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  31. )
  32. window.Promise ||
  33. document.write(
  34. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  35. )
  36. </script>
  37. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  38. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  39. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  40. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  41. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  42. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  43. </head>
  44. <body>
  45. <div id="app"></div>
  46. <div id="html">
  47. &lt;div id=&quot;chart&quot;&gt;
  48. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;line&quot; height={350} /&gt;
  49. &lt;/div&gt;
  50. </div>
  51. <script type="text/babel">
  52. class ApexChart extends React.Component {
  53. constructor(props) {
  54. super(props);
  55. this.state = {
  56. series: [{
  57. name: 'Income',
  58. type: 'column',
  59. data: [1.4, 2, 2.5, 1.5, 2.5, 2.8, 3.8, 4.6]
  60. }, {
  61. name: 'Cashflow',
  62. type: 'column',
  63. data: [1.1, 3, 3.1, 4, 4.1, 4.9, 6.5, 8.5]
  64. }, {
  65. name: 'Revenue',
  66. type: 'line',
  67. data: [20, 29, 37, 36, 44, 45, 50, 58]
  68. }],
  69. options: {
  70. chart: {
  71. height: 350,
  72. type: 'line',
  73. stacked: false
  74. },
  75. dataLabels: {
  76. enabled: false
  77. },
  78. stroke: {
  79. width: [1, 1, 4]
  80. },
  81. title: {
  82. text: 'XYZ - Stock Analysis (2009 - 2016)',
  83. align: 'left',
  84. offsetX: 110
  85. },
  86. xaxis: {
  87. categories: [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016],
  88. },
  89. yaxis: [
  90. {
  91. axisTicks: {
  92. show: true,
  93. },
  94. axisBorder: {
  95. show: true,
  96. color: '#008FFB'
  97. },
  98. labels: {
  99. style: {
  100. colors: '#008FFB',
  101. }
  102. },
  103. title: {
  104. text: "Income (thousand crores)",
  105. style: {
  106. color: '#008FFB',
  107. }
  108. },
  109. tooltip: {
  110. enabled: true
  111. }
  112. },
  113. {
  114. seriesName: 'Income',
  115. opposite: true,
  116. axisTicks: {
  117. show: true,
  118. },
  119. axisBorder: {
  120. show: true,
  121. color: '#00E396'
  122. },
  123. labels: {
  124. style: {
  125. colors: '#00E396',
  126. }
  127. },
  128. title: {
  129. text: "Operating Cashflow (thousand crores)",
  130. style: {
  131. color: '#00E396',
  132. }
  133. },
  134. },
  135. {
  136. seriesName: 'Revenue',
  137. opposite: true,
  138. axisTicks: {
  139. show: true,
  140. },
  141. axisBorder: {
  142. show: true,
  143. color: '#FEB019'
  144. },
  145. labels: {
  146. style: {
  147. colors: '#FEB019',
  148. },
  149. },
  150. title: {
  151. text: "Revenue (thousand crores)",
  152. style: {
  153. color: '#FEB019',
  154. }
  155. }
  156. },
  157. ],
  158. tooltip: {
  159. fixed: {
  160. enabled: true,
  161. position: 'topLeft', // topRight, topLeft, bottomRight, bottomLeft
  162. offsetY: 30,
  163. offsetX: 60
  164. },
  165. },
  166. legend: {
  167. horizontalAlign: 'left',
  168. offsetX: 40
  169. }
  170. },
  171. };
  172. }
  173. render() {
  174. return (
  175. <div>
  176. <div id="chart">
  177. <ReactApexChart options={this.state.options} series={this.state.series} type="line" height={350} />
  178. </div>
  179. <div id="html-dist"></div>
  180. </div>
  181. );
  182. }
  183. }
  184. const domContainer = document.querySelector('#app');
  185. ReactDOM.render(React.createElement(ApexChart), domContainer);
  186. </script>
  187. </body>
  188. </html>