candlestick-line.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 with Line Chart</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="../../assets/ohlc.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;line&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. name: 'line',
  51. type: 'line',
  52. data: [
  53. {
  54. x: new Date(1538778600000),
  55. y: 6604
  56. }, {
  57. x: new Date(1538782200000),
  58. y: 6602
  59. }, {
  60. x: new Date(1538814600000),
  61. y: 6607
  62. }, {
  63. x: new Date(1538884800000),
  64. y: 6620
  65. }
  66. ]
  67. }, {
  68. name: 'candle',
  69. type: 'candlestick',
  70. data: [
  71. {
  72. x: new Date(1538778600000),
  73. y: [6629.81, 6650.5, 6623.04, 6633.33]
  74. },
  75. {
  76. x: new Date(1538780400000),
  77. y: [6632.01, 6643.59, 6620, 6630.11]
  78. },
  79. {
  80. x: new Date(1538782200000),
  81. y: [6630.71, 6648.95, 6623.34, 6635.65]
  82. },
  83. {
  84. x: new Date(1538784000000),
  85. y: [6635.65, 6651, 6629.67, 6638.24]
  86. },
  87. {
  88. x: new Date(1538785800000),
  89. y: [6638.24, 6640, 6620, 6624.47]
  90. },
  91. {
  92. x: new Date(1538787600000),
  93. y: [6624.53, 6636.03, 6621.68, 6624.31]
  94. },
  95. {
  96. x: new Date(1538789400000),
  97. y: [6624.61, 6632.2, 6617, 6626.02]
  98. },
  99. {
  100. x: new Date(1538791200000),
  101. y: [6627, 6627.62, 6584.22, 6603.02]
  102. },
  103. {
  104. x: new Date(1538793000000),
  105. y: [6605, 6608.03, 6598.95, 6604.01]
  106. },
  107. {
  108. x: new Date(1538794800000),
  109. y: [6604.5, 6614.4, 6602.26, 6608.02]
  110. },
  111. {
  112. x: new Date(1538796600000),
  113. y: [6608.02, 6610.68, 6601.99, 6608.91]
  114. },
  115. {
  116. x: new Date(1538798400000),
  117. y: [6608.91, 6618.99, 6608.01, 6612]
  118. },
  119. {
  120. x: new Date(1538800200000),
  121. y: [6612, 6615.13, 6605.09, 6612]
  122. },
  123. {
  124. x: new Date(1538802000000),
  125. y: [6612, 6624.12, 6608.43, 6622.95]
  126. },
  127. {
  128. x: new Date(1538803800000),
  129. y: [6623.91, 6623.91, 6615, 6615.67]
  130. },
  131. {
  132. x: new Date(1538805600000),
  133. y: [6618.69, 6618.74, 6610, 6610.4]
  134. },
  135. {
  136. x: new Date(1538807400000),
  137. y: [6611, 6622.78, 6610.4, 6614.9]
  138. },
  139. {
  140. x: new Date(1538809200000),
  141. y: [6614.9, 6626.2, 6613.33, 6623.45]
  142. },
  143. {
  144. x: new Date(1538811000000),
  145. y: [6623.48, 6627, 6618.38, 6620.35]
  146. },
  147. {
  148. x: new Date(1538812800000),
  149. y: [6619.43, 6620.35, 6610.05, 6615.53]
  150. },
  151. {
  152. x: new Date(1538814600000),
  153. y: [6615.53, 6617.93, 6610, 6615.19]
  154. },
  155. {
  156. x: new Date(1538816400000),
  157. y: [6615.19, 6621.6, 6608.2, 6620]
  158. },
  159. {
  160. x: new Date(1538818200000),
  161. y: [6619.54, 6625.17, 6614.15, 6620]
  162. },
  163. {
  164. x: new Date(1538820000000),
  165. y: [6620.33, 6634.15, 6617.24, 6624.61]
  166. },
  167. {
  168. x: new Date(1538821800000),
  169. y: [6625.95, 6626, 6611.66, 6617.58]
  170. },
  171. {
  172. x: new Date(1538823600000),
  173. y: [6619, 6625.97, 6595.27, 6598.86]
  174. },
  175. {
  176. x: new Date(1538825400000),
  177. y: [6598.86, 6598.88, 6570, 6587.16]
  178. },
  179. {
  180. x: new Date(1538827200000),
  181. y: [6588.86, 6600, 6580, 6593.4]
  182. },
  183. {
  184. x: new Date(1538829000000),
  185. y: [6593.99, 6598.89, 6585, 6587.81]
  186. },
  187. {
  188. x: new Date(1538830800000),
  189. y: [6587.81, 6592.73, 6567.14, 6578]
  190. },
  191. {
  192. x: new Date(1538832600000),
  193. y: [6578.35, 6581.72, 6567.39, 6579]
  194. },
  195. {
  196. x: new Date(1538834400000),
  197. y: [6579.38, 6580.92, 6566.77, 6575.96]
  198. },
  199. {
  200. x: new Date(1538836200000),
  201. y: [6575.96, 6589, 6571.77, 6588.92]
  202. },
  203. {
  204. x: new Date(1538838000000),
  205. y: [6588.92, 6594, 6577.55, 6589.22]
  206. },
  207. {
  208. x: new Date(1538839800000),
  209. y: [6589.3, 6598.89, 6589.1, 6596.08]
  210. },
  211. {
  212. x: new Date(1538841600000),
  213. y: [6597.5, 6600, 6588.39, 6596.25]
  214. },
  215. {
  216. x: new Date(1538843400000),
  217. y: [6598.03, 6600, 6588.73, 6595.97]
  218. },
  219. {
  220. x: new Date(1538845200000),
  221. y: [6595.97, 6602.01, 6588.17, 6602]
  222. },
  223. {
  224. x: new Date(1538847000000),
  225. y: [6602, 6607, 6596.51, 6599.95]
  226. },
  227. {
  228. x: new Date(1538848800000),
  229. y: [6600.63, 6601.21, 6590.39, 6591.02]
  230. },
  231. {
  232. x: new Date(1538850600000),
  233. y: [6591.02, 6603.08, 6591, 6591]
  234. },
  235. {
  236. x: new Date(1538852400000),
  237. y: [6591, 6601.32, 6585, 6592]
  238. },
  239. {
  240. x: new Date(1538854200000),
  241. y: [6593.13, 6596.01, 6590, 6593.34]
  242. },
  243. {
  244. x: new Date(1538856000000),
  245. y: [6593.34, 6604.76, 6582.63, 6593.86]
  246. },
  247. {
  248. x: new Date(1538857800000),
  249. y: [6593.86, 6604.28, 6586.57, 6600.01]
  250. },
  251. {
  252. x: new Date(1538859600000),
  253. y: [6601.81, 6603.21, 6592.78, 6596.25]
  254. },
  255. {
  256. x: new Date(1538861400000),
  257. y: [6596.25, 6604.2, 6590, 6602.99]
  258. },
  259. {
  260. x: new Date(1538863200000),
  261. y: [6602.99, 6606, 6584.99, 6587.81]
  262. },
  263. {
  264. x: new Date(1538865000000),
  265. y: [6587.81, 6595, 6583.27, 6591.96]
  266. },
  267. {
  268. x: new Date(1538866800000),
  269. y: [6591.97, 6596.07, 6585, 6588.39]
  270. },
  271. {
  272. x: new Date(1538868600000),
  273. y: [6587.6, 6598.21, 6587.6, 6594.27]
  274. },
  275. {
  276. x: new Date(1538870400000),
  277. y: [6596.44, 6601, 6590, 6596.55]
  278. },
  279. {
  280. x: new Date(1538872200000),
  281. y: [6598.91, 6605, 6596.61, 6600.02]
  282. },
  283. {
  284. x: new Date(1538874000000),
  285. y: [6600.55, 6605, 6589.14, 6593.01]
  286. },
  287. {
  288. x: new Date(1538875800000),
  289. y: [6593.15, 6605, 6592, 6603.06]
  290. },
  291. {
  292. x: new Date(1538877600000),
  293. y: [6603.07, 6604.5, 6599.09, 6603.89]
  294. },
  295. {
  296. x: new Date(1538879400000),
  297. y: [6604.44, 6604.44, 6600, 6603.5]
  298. },
  299. {
  300. x: new Date(1538881200000),
  301. y: [6603.5, 6603.99, 6597.5, 6603.86]
  302. },
  303. {
  304. x: new Date(1538883000000),
  305. y: [6603.85, 6605, 6600, 6604.07]
  306. },
  307. {
  308. x: new Date(1538884800000),
  309. y: [6604.98, 6606, 6604.07, 6606]
  310. },
  311. ]
  312. }],
  313. options: {
  314. chart: {
  315. height: 350,
  316. type: 'line',
  317. },
  318. title: {
  319. text: 'CandleStick Chart',
  320. align: 'left'
  321. },
  322. stroke: {
  323. width: [3, 1]
  324. },
  325. tooltip: {
  326. shared: true,
  327. custom: [function({seriesIndex, dataPointIndex, w}) {
  328. return w.globals.series[seriesIndex][dataPointIndex]
  329. }, function({ seriesIndex, dataPointIndex, w }) {
  330. var o = w.globals.seriesCandleO[seriesIndex][dataPointIndex]
  331. var h = w.globals.seriesCandleH[seriesIndex][dataPointIndex]
  332. var l = w.globals.seriesCandleL[seriesIndex][dataPointIndex]
  333. var c = w.globals.seriesCandleC[seriesIndex][dataPointIndex]
  334. return (
  335. '<div class="apexcharts-tooltip-candlestick">' +
  336. '<div>Open: <span class="value">' +
  337. o +
  338. '</span></div>' +
  339. '<div>High: <span class="value">' +
  340. h +
  341. '</span></div>' +
  342. '<div>Low: <span class="value">' +
  343. l +
  344. '</span></div>' +
  345. '<div>Close: <span class="value">' +
  346. c +
  347. '</span></div>' +
  348. '</div>'
  349. )
  350. }]
  351. },
  352. xaxis: {
  353. type: 'datetime'
  354. }
  355. },
  356. };
  357. }
  358. render() {
  359. return (
  360. <div>
  361. <div id="chart">
  362. <ReactApexChart options={this.state.options} series={this.state.series} type="line" height={350} />
  363. </div>
  364. <div id="html-dist"></div>
  365. </div>
  366. );
  367. }
  368. }
  369. const domContainer = document.querySelector('#app');
  370. ReactDOM.render(React.createElement(ApexChart), domContainer);
  371. </script>
  372. </body>
  373. </html>