brush-charts.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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>Brush charts</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #wrapper {
  11. padding-top: 20px;
  12. padding-left: 10px;
  13. background: #fff;
  14. border: 1px solid #ddd;
  15. box-shadow: 0 22px 35px -16px rgba(0, 0, 0, 0.1);
  16. max-width: 650px;
  17. margin: 35px auto;
  18. }
  19. #chart-line {
  20. position: relative;
  21. margin-top: -40px;
  22. }
  23. </style>
  24. <script>
  25. window.Promise ||
  26. document.write(
  27. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  28. )
  29. window.Promise ||
  30. document.write(
  31. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  32. )
  33. window.Promise ||
  34. document.write(
  35. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  36. )
  37. </script>
  38. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  39. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  40. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  41. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  42. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  43. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  44. <script>
  45. /*
  46. // this function will generate output in this format
  47. // data = [
  48. [timestamp, 23],
  49. [timestamp, 33],
  50. [timestamp, 12]
  51. ...
  52. ]
  53. */
  54. function generateDayWiseTimeSeries(baseval, count, yrange) {
  55. var i = 0;
  56. var series = [];
  57. while (i < count) {
  58. var x = baseval;
  59. var y = Math.floor(Math.random() * (yrange.max - yrange.min + 1)) + yrange.min;
  60. series.push([x, y]);
  61. baseval += 86400000;
  62. i++;
  63. }
  64. return series;
  65. }
  66. var data = generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 185, {
  67. min: 30,
  68. max: 90
  69. })
  70. </script>
  71. </head>
  72. <body>
  73. <div id="app"></div>
  74. <div id="html">
  75. &lt;div id=&quot;wrapper&quot;&gt;
  76. &lt;div id=&quot;chart-line2&quot;&gt;
  77. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;line&quot; height={230} /&gt;
  78. &lt;/div&gt;
  79. &lt;div id=&quot;chart-line&quot;&gt;
  80. &lt;ReactApexChart options={this.state.optionsLine} series={this.state.seriesLine} type=&quot;area&quot; height={130} /&gt;
  81. &lt;/div&gt;
  82. &lt;/div&gt;
  83. </div>
  84. <script type="text/babel">
  85. class ApexChart extends React.Component {
  86. constructor(props) {
  87. super(props);
  88. this.state = {
  89. series: [{
  90. data: data
  91. }],
  92. options: {
  93. chart: {
  94. id: 'chart2',
  95. type: 'line',
  96. height: 230,
  97. toolbar: {
  98. autoSelected: 'pan',
  99. show: false
  100. }
  101. },
  102. colors: ['#546E7A'],
  103. stroke: {
  104. width: 3
  105. },
  106. dataLabels: {
  107. enabled: false
  108. },
  109. fill: {
  110. opacity: 1,
  111. },
  112. markers: {
  113. size: 0
  114. },
  115. xaxis: {
  116. type: 'datetime'
  117. }
  118. },
  119. seriesLine: [{
  120. data: data
  121. }],
  122. optionsLine: {
  123. chart: {
  124. id: 'chart1',
  125. height: 130,
  126. type: 'area',
  127. brush:{
  128. target: 'chart2',
  129. enabled: true
  130. },
  131. selection: {
  132. enabled: true,
  133. xaxis: {
  134. min: new Date('19 Jun 2017').getTime(),
  135. max: new Date('14 Aug 2017').getTime()
  136. }
  137. },
  138. },
  139. colors: ['#008FFB'],
  140. fill: {
  141. type: 'gradient',
  142. gradient: {
  143. opacityFrom: 0.91,
  144. opacityTo: 0.1,
  145. }
  146. },
  147. xaxis: {
  148. type: 'datetime',
  149. tooltip: {
  150. enabled: false
  151. }
  152. },
  153. yaxis: {
  154. tickAmount: 2
  155. }
  156. },
  157. };
  158. }
  159. render() {
  160. return (
  161. <div>
  162. <div id="wrapper">
  163. <div id="chart-line2">
  164. <ReactApexChart options={this.state.options} series={this.state.series} type="line" height={230} />
  165. </div>
  166. <div id="chart-line">
  167. <ReactApexChart options={this.state.optionsLine} series={this.state.seriesLine} type="area" height={130} />
  168. </div>
  169. </div>
  170. <div id="html-dist"></div>
  171. </div>
  172. );
  173. }
  174. }
  175. const domContainer = document.querySelector('#app');
  176. ReactDOM.render(React.createElement(ApexChart), domContainer);
  177. </script>
  178. </body>
  179. </html>