annotations-example.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/vue/dist/vue.min.js"></script>
  30. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  31. <script src="https://cdn.jsdelivr.net/npm/vue-apexcharts"></script>
  32. <script src="../../assets/stock-prices.js"></script>
  33. </head>
  34. <body>
  35. <div id="app">
  36. <div id="chart">
  37. <apexchart type="line" ref="chart" :options="chartOptions" :series="series"></apexchart>
  38. </div>
  39. </div>
  40. <!-- Below element is just for displaying source code. it is not required. DO NOT USE -->
  41. <div id="html">
  42. &lt;div id=&quot;chart&quot;&gt;
  43. &lt;apexchart type=&quot;line&quot; ref=&quot;chart&quot; :options=&quot;chartOptions&quot; :series=&quot;series&quot;&gt;&lt;/apexchart&gt;
  44. &lt;/div&gt;
  45. </div>
  46. <script>
  47. new Vue({
  48. el: '#app',
  49. components: {
  50. apexchart: VueApexCharts,
  51. },
  52. data: {
  53. series: [{
  54. type: 'bar',
  55. data: series.monthDataSeries2.prices
  56. }, {
  57. type: 'line',
  58. data: series.monthDataSeries1.prices
  59. }],
  60. chartOptions: {
  61. chart: {
  62. type: 'line',
  63. id: 'chart',
  64. sparkline: {
  65. // enabled: true
  66. }
  67. },
  68. annotations: {
  69. yaxis: [{
  70. y: 8200,
  71. borderColor: '#FEB019',
  72. label: {
  73. borderColor: '#333',
  74. style: {
  75. fontSize: '15px',
  76. color: '#333',
  77. background: '#FEB019',
  78. },
  79. text: 'Y-axis annotation',
  80. }
  81. }],
  82. xaxis: [{
  83. x: new Date('23 Nov 2017').getTime(),
  84. borderColor: '#00E396',
  85. label: {
  86. borderColor: '#00E396',
  87. style: {
  88. fontSize: '15px',
  89. color: '#fff',
  90. background: '#00E396',
  91. },
  92. offsetY: -10,
  93. text: 'Vertical',
  94. }
  95. }],
  96. points: [{
  97. x: new Date('01 Dec 2017').getTime(),
  98. y: 9025,
  99. label: {
  100. borderColor: '#FF4560',
  101. offsetY: 0,
  102. style: {
  103. fontSize: '15px',
  104. color: '#fff',
  105. background: '#FF4560',
  106. },
  107. text: 'All time high',
  108. }
  109. }]
  110. },
  111. plotOptions: {
  112. bar: {
  113. columnWidth: '50%'
  114. }
  115. },
  116. markers: {
  117. size: 0
  118. },
  119. dataLabels: {
  120. enabled: false
  121. },
  122. stroke: {
  123. curve: 'straight'
  124. },
  125. legend: {
  126. show: false,
  127. },
  128. labels: series.monthDataSeries1.dates,
  129. xaxis: {
  130. type: 'datetime',
  131. }
  132. },
  133. },
  134. mounted: function() {
  135. this.$refs.chart.addYaxisAnnotation({
  136. id: 'yaxis-anno',
  137. y: 9000,
  138. borderColor: '#FEB019',
  139. label: {
  140. borderColor: '#333',
  141. style: {
  142. fontSize: '15px',
  143. color: '#333',
  144. background: '#FEB019',
  145. },
  146. text: 'Y-axis - runtime',
  147. }
  148. });
  149. this.$refs.chart.addXaxisAnnotation({
  150. id: 'xaxis-anno',
  151. x: new Date('25 Nov 2017').getTime(),
  152. borderColor: '#00E396',
  153. label: {
  154. orientation: 'vertical',
  155. borderColor: '#00E396',
  156. style: {
  157. fontSize: '15px',
  158. color: '#fff',
  159. background: '#00E396',
  160. },
  161. offsetY: -10,
  162. text: 'xaxis - runtime',
  163. }
  164. });
  165. this.$refs.chart.addPointAnnotation({
  166. id: 'point-anno',
  167. x: new Date('17 Nov 2017').getTime(),
  168. y: 9425,
  169. label: {
  170. borderColor: '#FF4560',
  171. offsetY: 0,
  172. style: {
  173. fontSize: '15px',
  174. color: '#fff',
  175. background: '#FF4560',
  176. },
  177. text: 'Point - runtime',
  178. }
  179. });
  180. this.$refs.chart.removeAnnotation('point-anno');
  181. },
  182. })
  183. </script>
  184. </body>
  185. </html>