candlestick-bar.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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>CandleStick Chart with Bar</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. .chart-box {
  11. max-width: 650px;
  12. margin: 35px auto;
  13. }
  14. #chart-candlestick,
  15. #chart-bar {
  16. max-width: 640px;
  17. }
  18. #chart-bar {
  19. margin-top: -30px;
  20. }
  21. </style>
  22. <script>
  23. window.Promise ||
  24. document.write(
  25. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  26. )
  27. window.Promise ||
  28. document.write(
  29. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  30. )
  31. window.Promise ||
  32. document.write(
  33. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  34. )
  35. </script>
  36. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  37. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  38. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  39. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  40. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  41. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  42. <script src="../../assets/ohlc.js"></script>
  43. </head>
  44. <body>
  45. <div id="app"></div>
  46. <div id="html">
  47. &lt;div class=&quot;chart-box&quot;&gt;
  48. &lt;div id=&quot;chart-candlestick&quot;&gt;
  49. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;candlestick&quot; height={290} /&gt;
  50. &lt;/div&gt;
  51. &lt;div id=&quot;chart-bar&quot;&gt;
  52. &lt;ReactApexChart options={this.state.optionsBar} series={this.state.seriesBar} type=&quot;bar&quot; height={160} /&gt;
  53. &lt;/div&gt;
  54. &lt;/div&gt;
  55. </div>
  56. <script type="text/babel">
  57. class ApexChart extends React.Component {
  58. constructor(props) {
  59. super(props);
  60. this.state = {
  61. series: [{
  62. data: seriesData
  63. }],
  64. options: {
  65. chart: {
  66. type: 'candlestick',
  67. height: 290,
  68. id: 'candles',
  69. toolbar: {
  70. autoSelected: 'pan',
  71. show: false
  72. },
  73. zoom: {
  74. enabled: false
  75. },
  76. },
  77. plotOptions: {
  78. candlestick: {
  79. colors: {
  80. upward: '#3C90EB',
  81. downward: '#DF7D46'
  82. }
  83. }
  84. },
  85. xaxis: {
  86. type: 'datetime'
  87. }
  88. },
  89. seriesBar: [{
  90. name: 'volume',
  91. data: seriesDataLinear
  92. }],
  93. optionsBar: {
  94. chart: {
  95. height: 160,
  96. type: 'bar',
  97. brush: {
  98. enabled: true,
  99. target: 'candles'
  100. },
  101. selection: {
  102. enabled: true,
  103. xaxis: {
  104. min: new Date('20 Jan 2017').getTime(),
  105. max: new Date('10 Dec 2017').getTime()
  106. },
  107. fill: {
  108. color: '#ccc',
  109. opacity: 0.4
  110. },
  111. stroke: {
  112. color: '#0D47A1',
  113. }
  114. },
  115. },
  116. dataLabels: {
  117. enabled: false
  118. },
  119. plotOptions: {
  120. bar: {
  121. columnWidth: '80%',
  122. colors: {
  123. ranges: [{
  124. from: -1000,
  125. to: 0,
  126. color: '#F15B46'
  127. }, {
  128. from: 1,
  129. to: 10000,
  130. color: '#FEB019'
  131. }],
  132. },
  133. }
  134. },
  135. stroke: {
  136. width: 0
  137. },
  138. xaxis: {
  139. type: 'datetime',
  140. axisBorder: {
  141. offsetX: 13
  142. }
  143. },
  144. yaxis: {
  145. labels: {
  146. show: false
  147. }
  148. }
  149. },
  150. };
  151. }
  152. render() {
  153. return (
  154. <div>
  155. <div class="chart-box">
  156. <div id="chart-candlestick">
  157. <ReactApexChart options={this.state.options} series={this.state.series} type="candlestick" height={290} />
  158. </div>
  159. <div id="chart-bar">
  160. <ReactApexChart options={this.state.optionsBar} series={this.state.seriesBar} type="bar" height={160} />
  161. </div>
  162. </div>
  163. <div id="html-dist"></div>
  164. </div>
  165. );
  166. }
  167. }
  168. const domContainer = document.querySelector('#app');
  169. ReactDOM.render(React.createElement(ApexChart), domContainer);
  170. </script>
  171. </body>
  172. </html>