annotations-example.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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>Line Chart with Annotations</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 src="../../assets/stock-prices.js"></script>
  36. </head>
  37. <body>
  38. <div id="app"></div>
  39. <div id="html">
  40. &lt;div id=&quot;chart&quot;&gt;
  41. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;line&quot; /&gt;
  42. &lt;/div&gt;
  43. </div>
  44. <script type="text/babel">
  45. class ApexChart extends React.Component {
  46. constructor(props) {
  47. super(props);
  48. this.state = {
  49. series: [{
  50. type: 'bar',
  51. data: series.monthDataSeries2.prices
  52. }, {
  53. type: 'line',
  54. data: series.monthDataSeries1.prices
  55. }],
  56. options: {
  57. chart: {
  58. type: 'line',
  59. id: 'chart',
  60. sparkline: {
  61. // enabled: true
  62. }
  63. },
  64. annotations: {
  65. yaxis: [{
  66. y: 8200,
  67. borderColor: '#FEB019',
  68. label: {
  69. borderColor: '#333',
  70. style: {
  71. fontSize: '15px',
  72. color: '#333',
  73. background: '#FEB019',
  74. },
  75. text: 'Y-axis annotation',
  76. }
  77. }],
  78. xaxis: [{
  79. x: new Date('23 Nov 2017').getTime(),
  80. borderColor: '#00E396',
  81. label: {
  82. borderColor: '#00E396',
  83. style: {
  84. fontSize: '15px',
  85. color: '#fff',
  86. background: '#00E396',
  87. },
  88. offsetY: -10,
  89. text: 'Vertical',
  90. }
  91. }],
  92. points: [{
  93. x: new Date('01 Dec 2017').getTime(),
  94. y: 9025,
  95. label: {
  96. borderColor: '#FF4560',
  97. offsetY: 0,
  98. style: {
  99. fontSize: '15px',
  100. color: '#fff',
  101. background: '#FF4560',
  102. },
  103. text: 'All time high',
  104. }
  105. }]
  106. },
  107. plotOptions: {
  108. bar: {
  109. columnWidth: '50%'
  110. }
  111. },
  112. markers: {
  113. size: 0
  114. },
  115. dataLabels: {
  116. enabled: false
  117. },
  118. stroke: {
  119. curve: 'straight'
  120. },
  121. legend: {
  122. show: false,
  123. },
  124. labels: series.monthDataSeries1.dates,
  125. xaxis: {
  126. type: 'datetime',
  127. }
  128. },
  129. };
  130. }
  131. componentDidMount() {
  132. ApexCharts.exec('chart', 'addYaxisAnnotation', {
  133. id: 'yaxis-anno',
  134. y: 9000,
  135. borderColor: '#FEB019',
  136. label: {
  137. borderColor: '#333',
  138. style: {
  139. fontSize: '15px',
  140. color: '#333',
  141. background: '#FEB019',
  142. },
  143. text: 'Y-axis - runtime',
  144. }
  145. });
  146. ApexCharts.exec('chart', 'addXaxisAnnotation', {
  147. id: 'xaxis-anno',
  148. x: new Date('25 Nov 2017').getTime(),
  149. borderColor: '#00E396',
  150. label: {
  151. orientation: 'vertical',
  152. borderColor: '#00E396',
  153. style: {
  154. fontSize: '15px',
  155. color: '#fff',
  156. background: '#00E396',
  157. },
  158. offsetY: -10,
  159. text: 'xaxis - runtime',
  160. }
  161. });
  162. ApexCharts.exec('chart', 'addPointAnnotation', {
  163. id: 'point-anno',
  164. x: new Date('17 Nov 2017').getTime(),
  165. y: 9425,
  166. label: {
  167. borderColor: '#FF4560',
  168. offsetY: 0,
  169. style: {
  170. fontSize: '15px',
  171. color: '#fff',
  172. background: '#FF4560',
  173. },
  174. text: 'Point - runtime',
  175. }
  176. });
  177. ApexCharts.exec('chart', 'removeAnnotation', 'point-anno');
  178. }
  179. render() {
  180. return (
  181. <div>
  182. <div id="chart">
  183. <ReactApexChart options={this.state.options} series={this.state.series} type="line" />
  184. </div>
  185. <div id="html-dist"></div>
  186. </div>
  187. );
  188. }
  189. }
  190. const domContainer = document.querySelector('#app');
  191. ReactDOM.render(React.createElement(ApexChart), domContainer);
  192. </script>
  193. </body>
  194. </html>