multi-series.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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>Multi-series Timeline</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/react@16.12/umd/react.production.min.js"></script>
  30. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  31. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  32. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  33. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  34. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  35. <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
  36. </head>
  37. <body>
  38. <div id="app"></div>
  39. <div id="html">
  40. &lt;div id=&quot;chart&quot;&gt;
  41. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;rangeBar&quot; height={350} /&gt;
  42. &lt;/div&gt;
  43. </div>
  44. <script type="text/babel">
  45. class ApexChart extends React.Component {
  46. constructor(props) {
  47. super(props);
  48. this.state = {
  49. series: [
  50. {
  51. name: 'Bob',
  52. data: [
  53. {
  54. x: 'Design',
  55. y: [
  56. new Date('2019-03-05').getTime(),
  57. new Date('2019-03-08').getTime()
  58. ]
  59. },
  60. {
  61. x: 'Code',
  62. y: [
  63. new Date('2019-03-08').getTime(),
  64. new Date('2019-03-11').getTime()
  65. ]
  66. },
  67. {
  68. x: 'Test',
  69. y: [
  70. new Date('2019-03-11').getTime(),
  71. new Date('2019-03-16').getTime()
  72. ]
  73. }
  74. ]
  75. },
  76. {
  77. name: 'Joe',
  78. data: [
  79. {
  80. x: 'Design',
  81. y: [
  82. new Date('2019-03-02').getTime(),
  83. new Date('2019-03-05').getTime()
  84. ]
  85. },
  86. {
  87. x: 'Code',
  88. y: [
  89. new Date('2019-03-06').getTime(),
  90. new Date('2019-03-09').getTime()
  91. ]
  92. },
  93. {
  94. x: 'Test',
  95. y: [
  96. new Date('2019-03-10').getTime(),
  97. new Date('2019-03-19').getTime()
  98. ]
  99. }
  100. ]
  101. }
  102. ],
  103. options: {
  104. chart: {
  105. height: 350,
  106. type: 'rangeBar'
  107. },
  108. plotOptions: {
  109. bar: {
  110. horizontal: true
  111. }
  112. },
  113. dataLabels: {
  114. enabled: true,
  115. formatter: function(val) {
  116. var a = moment(val[0])
  117. var b = moment(val[1])
  118. var diff = b.diff(a, 'days')
  119. return diff + (diff > 1 ? ' days' : ' day')
  120. }
  121. },
  122. fill: {
  123. type: 'gradient',
  124. gradient: {
  125. shade: 'light',
  126. type: 'vertical',
  127. shadeIntensity: 0.25,
  128. gradientToColors: undefined,
  129. inverseColors: true,
  130. opacityFrom: 1,
  131. opacityTo: 1,
  132. stops: [50, 0, 100, 100]
  133. }
  134. },
  135. xaxis: {
  136. type: 'datetime'
  137. },
  138. legend: {
  139. position: 'top'
  140. }
  141. },
  142. };
  143. }
  144. render() {
  145. return (
  146. <div>
  147. <div id="chart">
  148. <ReactApexChart options={this.state.options} series={this.state.series} type="rangeBar" height={350} />
  149. </div>
  150. <div id="html-dist"></div>
  151. </div>
  152. );
  153. }
  154. }
  155. const domContainer = document.querySelector('#app');
  156. ReactDOM.render(React.createElement(ApexChart), domContainer);
  157. </script>
  158. </body>
  159. </html>