range-annotations-example.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 Range 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. </head>
  16. <body>
  17. <div id="chart">
  18. </div>
  19. <script src="https://cdn.jsdelivr.net/npm/apexcharts@latest"></script>
  20. <script src="../../assets/stock-prices.js"></script>
  21. <script>
  22. var options = {
  23. annotations: {
  24. yaxis: [{
  25. y: 8600,
  26. y2: 9000,
  27. borderColor: '#FEB019',
  28. opacity: 0.1,
  29. label: {
  30. borderColor: '#333',
  31. style: {
  32. fontSize: '10px',
  33. color: '#333',
  34. background: '#FEB019',
  35. },
  36. text: 'Y-axis range',
  37. }
  38. }],
  39. xaxis: [{
  40. x: new Date('23 Nov 2017').getTime(),
  41. x2: new Date('28 Nov 2017').getTime(),
  42. borderColor: '#00E396',
  43. opacity: 0.5,
  44. label: {
  45. borderColor: '#00E396',
  46. style: {
  47. fontSize: '10px',
  48. color: '#fff',
  49. background: '#00E396',
  50. },
  51. offsetY: -10,
  52. text: 'X-axis range',
  53. }
  54. }]
  55. },
  56. chart: {
  57. width: 350,
  58. height: 220,
  59. type: 'line',
  60. sparkline: {
  61. // enabled: true
  62. }
  63. },
  64. plotOptions: {
  65. bar: {
  66. columnWidth: '50%'
  67. }
  68. },
  69. markers: {
  70. size: 0
  71. },
  72. dataLabels: {
  73. enabled: false
  74. },
  75. stroke: {
  76. curve: 'straight'
  77. },
  78. series: [ {
  79. type: 'bar',
  80. data: series.monthDataSeries2.prices
  81. }, {
  82. type: 'line',
  83. data: series.monthDataSeries1.prices
  84. }],
  85. legend: {
  86. show: false,
  87. },
  88. labels: series.monthDataSeries1.dates,
  89. xaxis: {
  90. type: 'datetime',
  91. labels: {
  92. show: false
  93. }
  94. },
  95. yaxis: {
  96. labels: {
  97. show: false
  98. }
  99. }
  100. }
  101. var chart = new ApexCharts(
  102. document.querySelector("#chart"),
  103. options
  104. );
  105. chart.render();
  106. // adding annotation through chart instance by calling direct method
  107. chart.addYaxisAnnotation({
  108. y: 9200,
  109. y2: 9400,
  110. borderColor: '#64b5f6',
  111. label: {
  112. borderColor: '#333',
  113. style: {
  114. fontSize: '10px',
  115. color: '#333',
  116. background: '#64b5f6',
  117. },
  118. text: 'Y-axis - runtime',
  119. }
  120. });
  121. chart.addXaxisAnnotation({
  122. x: new Date('16 Nov 2017').getTime(),
  123. x2: new Date('18 Nov 2017').getTime(),
  124. borderColor: '#ef9a9a',
  125. label: {
  126. orientation: 'vertical',
  127. borderColor: '#ef9a9a',
  128. style: {
  129. fontSize: '10px',
  130. color: '#fff',
  131. background: '#ef9a9a',
  132. },
  133. offsetY: -10,
  134. text: 'X-axis - runtime',
  135. }
  136. });
  137. </script>
  138. </body>
  139. </html>