syncing-charts.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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/vue/dist/vue.min.js"></script>
  35. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  36. <script src="https://cdn.jsdelivr.net/npm/vue-apexcharts"></script>
  37. <script>
  38. // The global window.Apex variable below can be used to set common options for all charts on the page
  39. Apex = {
  40. chart: {
  41. height: 160,
  42. },
  43. dataLabels: {
  44. enabled: false
  45. },
  46. stroke: {
  47. curve: 'straight'
  48. },
  49. toolbar: {
  50. tools: {
  51. selection: false
  52. }
  53. },
  54. markers: {
  55. size: 6,
  56. hover: {
  57. size: 10
  58. }
  59. },
  60. tooltip: {
  61. followCursor: false,
  62. theme: 'dark',
  63. x: {
  64. show: false
  65. },
  66. marker: {
  67. show: false
  68. },
  69. y: {
  70. title: {
  71. formatter: function() {
  72. return ''
  73. }
  74. }
  75. }
  76. },
  77. grid: {
  78. clipMarkers: false
  79. },
  80. yaxis: {
  81. tickAmount: 2
  82. },
  83. xaxis: {
  84. type: 'datetime'
  85. },
  86. }
  87. /*
  88. // this function will generate output in this format
  89. // data = [
  90. [timestamp, 23],
  91. [timestamp, 33],
  92. [timestamp, 12]
  93. ...
  94. ]
  95. */
  96. function generateDayWiseTimeSeries(baseval, count, yrange) {
  97. var i = 0;
  98. var series = [];
  99. while (i < count) {
  100. var x = baseval;
  101. var y = Math.floor(Math.random() * (yrange.max - yrange.min + 1)) + yrange.min;
  102. series.push([x, y]);
  103. baseval += 86400000;
  104. i++;
  105. }
  106. return series;
  107. }
  108. </script>
  109. </head>
  110. <body>
  111. <div id="app">
  112. <div id="wrapper">
  113. <div id="chart-line">
  114. <apexchart type="line" height="160" :options="chartOptions" :series="series"></apexchart>
  115. </div>
  116. <div id="chart-line2">
  117. <apexchart type="line" height="160" :options="chartOptionsLine2" :series="seriesLine2"></apexchart>
  118. </div>
  119. <div id="chart-area">
  120. <apexchart type="area" height="160" :options="chartOptionsArea" :series="seriesArea"></apexchart>
  121. </div>
  122. </div>
  123. </div>
  124. <!-- Below element is just for displaying source code. it is not required. DO NOT USE -->
  125. <div id="html">
  126. &lt;div id=&quot;wrapper&quot;&gt;
  127. &lt;div id=&quot;chart-line&quot;&gt;
  128. &lt;apexchart type=&quot;line&quot; height=&quot;160&quot; :options=&quot;chartOptions&quot; :series=&quot;series&quot;&gt;&lt;/apexchart&gt;
  129. &lt;/div&gt;
  130. &lt;div id=&quot;chart-line2&quot;&gt;
  131. &lt;apexchart type=&quot;line&quot; height=&quot;160&quot; :options=&quot;chartOptionsLine2&quot; :series=&quot;seriesLine2&quot;&gt;&lt;/apexchart&gt;
  132. &lt;/div&gt;
  133. &lt;div id=&quot;chart-area&quot;&gt;
  134. &lt;apexchart type=&quot;area&quot; height=&quot;160&quot; :options=&quot;chartOptionsArea&quot; :series=&quot;seriesArea&quot;&gt;&lt;/apexchart&gt;
  135. &lt;/div&gt;
  136. &lt;/div&gt;
  137. </div>
  138. <script>
  139. new Vue({
  140. el: '#app',
  141. components: {
  142. apexchart: VueApexCharts,
  143. },
  144. data: {
  145. series: [{
  146. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  147. min: 10,
  148. max: 60
  149. })
  150. }],
  151. chartOptions: {
  152. chart: {
  153. id: 'fb',
  154. group: 'social',
  155. type: 'line',
  156. height: 160
  157. },
  158. colors: ['#008FFB'],
  159. yaxis: {
  160. labels: {
  161. minWidth: 40
  162. }
  163. }
  164. },
  165. seriesLine2: [{
  166. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  167. min: 10,
  168. max: 30
  169. })
  170. }],
  171. chartOptionsLine2: {
  172. chart: {
  173. id: 'tw',
  174. group: 'social',
  175. type: 'line',
  176. height: 160
  177. },
  178. colors: ['#546E7A'],
  179. yaxis: {
  180. labels: {
  181. minWidth: 40
  182. }
  183. }
  184. },
  185. seriesArea: [{
  186. data: generateDayWiseTimeSeries(new Date('11 Feb 2017').getTime(), 20, {
  187. min: 10,
  188. max: 60
  189. })
  190. }],
  191. chartOptionsArea: {
  192. chart: {
  193. id: 'yt',
  194. group: 'social',
  195. type: 'area',
  196. height: 160
  197. },
  198. colors: ['#00E396'],
  199. yaxis: {
  200. labels: {
  201. minWidth: 40
  202. }
  203. }
  204. },
  205. },
  206. })
  207. </script>
  208. </body>
  209. </html>