syncing-charts.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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>Syncing 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. </style>
  20. <script>
  21. window.Promise ||
  22. document.write(
  23. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  24. )
  25. window.Promise ||
  26. document.write(
  27. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  28. )
  29. window.Promise ||
  30. document.write(
  31. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  32. )
  33. </script>
  34. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  35. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  36. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  37. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  38. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  39. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  40. <script>
  41. // The global window.Apex variable below can be used to set common options for all charts on the page
  42. Apex = {
  43. chart: {
  44. height: 160,
  45. },
  46. dataLabels: {
  47. enabled: false
  48. },
  49. stroke: {
  50. curve: 'straight'
  51. },
  52. toolbar: {
  53. tools: {
  54. selection: false
  55. }
  56. },
  57. markers: {
  58. size: 6,
  59. hover: {
  60. size: 10
  61. }
  62. },
  63. tooltip: {
  64. followCursor: false,
  65. theme: 'dark',
  66. x: {
  67. show: false
  68. },
  69. marker: {
  70. show: false
  71. },
  72. y: {
  73. title: {
  74. formatter: function() {
  75. return ''
  76. }
  77. }
  78. }
  79. },
  80. grid: {
  81. clipMarkers: false
  82. },
  83. yaxis: {
  84. tickAmount: 2
  85. },
  86. xaxis: {
  87. type: 'datetime'
  88. },
  89. }
  90. /*
  91. // this function will generate output in this format
  92. // data = [
  93. [timestamp, 23],
  94. [timestamp, 33],
  95. [timestamp, 12]
  96. ...
  97. ]
  98. */
  99. function generateDayWiseTimeSeries(baseval, count, yrange) {
  100. var i = 0;
  101. var series = [];
  102. while (i < count) {
  103. var x = baseval;
  104. var y = Math.floor(Math.random() * (yrange.max - yrange.min + 1)) + yrange.min;
  105. series.push([x, y]);
  106. baseval += 86400000;
  107. i++;
  108. }
  109. return series;
  110. }
  111. </script>
  112. </head>
  113. <body>
  114. <div id="app"></div>
  115. <div id="html">
  116. &lt;div id=&quot;wrapper&quot;&gt;
  117. &lt;div id=&quot;chart-line&quot;&gt;
  118. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;line&quot; height={160} /&gt;
  119. &lt;/div&gt;
  120. &lt;div id=&quot;chart-line2&quot;&gt;
  121. &lt;ReactApexChart options={this.state.optionsLine2} series={this.state.seriesLine2} type=&quot;line&quot; height={160} /&gt;
  122. &lt;/div&gt;
  123. &lt;div id=&quot;chart-area&quot;&gt;
  124. &lt;ReactApexChart options={this.state.optionsArea} series={this.state.seriesArea} type=&quot;area&quot; height={160} /&gt;
  125. &lt;/div&gt;
  126. &lt;/div&gt;
  127. </div>
  128. <script type="text/babel">
  129. class ApexChart extends React.Component {
  130. constructor(props) {
  131. super(props);
  132. this.state = {
  133. series: [{
  134. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  135. min: 10,
  136. max: 60
  137. })
  138. }],
  139. options: {
  140. chart: {
  141. id: 'fb',
  142. group: 'social',
  143. type: 'line',
  144. height: 160
  145. },
  146. colors: ['#008FFB'],
  147. yaxis: {
  148. labels: {
  149. minWidth: 40
  150. }
  151. }
  152. },
  153. seriesLine2: [{
  154. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  155. min: 10,
  156. max: 30
  157. })
  158. }],
  159. optionsLine2: {
  160. chart: {
  161. id: 'tw',
  162. group: 'social',
  163. type: 'line',
  164. height: 160
  165. },
  166. colors: ['#546E7A'],
  167. yaxis: {
  168. labels: {
  169. minWidth: 40
  170. }
  171. }
  172. },
  173. seriesArea: [{
  174. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  175. min: 10,
  176. max: 60
  177. })
  178. }],
  179. optionsArea: {
  180. chart: {
  181. id: 'yt',
  182. group: 'social',
  183. type: 'area',
  184. height: 160
  185. },
  186. colors: ['#00E396'],
  187. yaxis: {
  188. labels: {
  189. minWidth: 40
  190. }
  191. }
  192. },
  193. };
  194. }
  195. render() {
  196. return (
  197. <div>
  198. <div id="wrapper">
  199. <div id="chart-line">
  200. <ReactApexChart options={this.state.options} series={this.state.series} type="line" height={160} />
  201. </div>
  202. <div id="chart-line2">
  203. <ReactApexChart options={this.state.optionsLine2} series={this.state.seriesLine2} type="line" height={160} />
  204. </div>
  205. <div id="chart-area">
  206. <ReactApexChart options={this.state.optionsArea} series={this.state.seriesArea} type="area" height={160} />
  207. </div>
  208. </div>
  209. <div id="html-dist"></div>
  210. </div>
  211. );
  212. }
  213. }
  214. const domContainer = document.querySelector('#app');
  215. ReactDOM.render(React.createElement(ApexChart), domContainer);
  216. </script>
  217. </body>
  218. </html>