area-datetime.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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>Area Chart - Datetime X-Axis</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. #chart {
  11. max-width: 650px;
  12. margin: 35px auto;
  13. }
  14. .toolbar {
  15. margin-left: 45px;
  16. }
  17. button {
  18. background: #fff;
  19. color: #222;
  20. border: 1px solid #e7e7e7;
  21. border-bottom: 2px solid #ddd;
  22. border-radius: 2px;
  23. padding: 4px 17px;
  24. }
  25. button.active {
  26. color: #fff;
  27. background: #008FFB;
  28. border: 1px solid blue;
  29. border-bottom: 2px solid blue;
  30. }
  31. button:focus {
  32. outline: 0;
  33. }
  34. </style>
  35. <script>
  36. window.Promise ||
  37. document.write(
  38. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  39. )
  40. window.Promise ||
  41. document.write(
  42. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  43. )
  44. window.Promise ||
  45. document.write(
  46. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  47. )
  48. </script>
  49. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  50. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  51. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  52. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  53. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  54. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  55. </head>
  56. <body>
  57. <div id="app"></div>
  58. <div id="html">
  59. &lt;div id=&quot;chart&quot;&gt;
  60. &lt;div class=&quot;toolbar&quot;&gt;
  61. &lt;button id=&quot;one_month&quot;
  62. onClick={()=&gt;this.updateData(&#39;one_month&#39;)} className={ (this.state.selection===&#39;one_month&#39; ? &#39;active&#39; : &#39;&#39;)}&gt;
  63. 1M
  64. &lt;/button&gt;
  65. &amp;nbsp;
  66. &lt;button id=&quot;six_months&quot;
  67. onClick={()=&gt;this.updateData(&#39;six_months&#39;)} className={ (this.state.selection===&#39;six_months&#39; ? &#39;active&#39; : &#39;&#39;)}&gt;
  68. 6M
  69. &lt;/button&gt;
  70. &amp;nbsp;
  71. &lt;button id=&quot;one_year&quot;
  72. onClick={()=&gt;this.updateData(&#39;one_year&#39;)} className={ (this.state.selection===&#39;one_year&#39; ? &#39;active&#39; : &#39;&#39;)}&gt;
  73. 1Y
  74. &lt;/button&gt;
  75. &amp;nbsp;
  76. &lt;button id=&quot;ytd&quot;
  77. onClick={()=&gt;this.updateData(&#39;ytd&#39;)} className={ (this.state.selection===&#39;ytd&#39; ? &#39;active&#39; : &#39;&#39;)}&gt;
  78. YTD
  79. &lt;/button&gt;
  80. &amp;nbsp;
  81. &lt;button id=&quot;all&quot;
  82. onClick={()=&gt;this.updateData(&#39;all&#39;)} className={ (this.state.selection===&#39;all&#39; ? &#39;active&#39; : &#39;&#39;)}&gt;
  83. ALL
  84. &lt;/button&gt;
  85. &lt;/div&gt;
  86. &lt;div id=&quot;chart-timeline&quot;&gt;
  87. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;area&quot; height={350} /&gt;
  88. &lt;/div&gt;
  89. &lt;/div&gt;
  90. </div>
  91. <script type="text/babel">
  92. class ApexChart extends React.Component {
  93. constructor(props) {
  94. super(props);
  95. this.state = {
  96. series: [{
  97. data: [
  98. [1327359600000,30.95],
  99. [1327446000000,31.34],
  100. [1327532400000,31.18],
  101. [1327618800000,31.05],
  102. [1327878000000,31.00],
  103. [1327964400000,30.95],
  104. [1328050800000,31.24],
  105. [1328137200000,31.29],
  106. [1328223600000,31.85],
  107. [1328482800000,31.86],
  108. [1328569200000,32.28],
  109. [1328655600000,32.10],
  110. [1328742000000,32.65],
  111. [1328828400000,32.21],
  112. [1329087600000,32.35],
  113. [1329174000000,32.44],
  114. [1329260400000,32.46],
  115. [1329346800000,32.86],
  116. [1329433200000,32.75],
  117. [1329778800000,32.54],
  118. [1329865200000,32.33],
  119. [1329951600000,32.97],
  120. [1330038000000,33.41],
  121. [1330297200000,33.27],
  122. [1330383600000,33.27],
  123. [1330470000000,32.89],
  124. [1330556400000,33.10],
  125. [1330642800000,33.73],
  126. [1330902000000,33.22],
  127. [1330988400000,31.99],
  128. [1331074800000,32.41],
  129. [1331161200000,33.05],
  130. [1331247600000,33.64],
  131. [1331506800000,33.56],
  132. [1331593200000,34.22],
  133. [1331679600000,33.77],
  134. [1331766000000,34.17],
  135. [1331852400000,33.82],
  136. [1332111600000,34.51],
  137. [1332198000000,33.16],
  138. [1332284400000,33.56],
  139. [1332370800000,33.71],
  140. [1332457200000,33.81],
  141. [1332712800000,34.40],
  142. [1332799200000,34.63],
  143. [1332885600000,34.46],
  144. [1332972000000,34.48],
  145. [1333058400000,34.31],
  146. [1333317600000,34.70],
  147. [1333404000000,34.31],
  148. [1333490400000,33.46],
  149. [1333576800000,33.59],
  150. [1333922400000,33.22],
  151. [1334008800000,32.61],
  152. [1334095200000,33.01],
  153. [1334181600000,33.55],
  154. [1334268000000,33.18],
  155. [1334527200000,32.84],
  156. [1334613600000,33.84],
  157. [1334700000000,33.39],
  158. [1334786400000,32.91],
  159. [1334872800000,33.06],
  160. [1335132000000,32.62],
  161. [1335218400000,32.40],
  162. [1335304800000,33.13],
  163. [1335391200000,33.26],
  164. [1335477600000,33.58],
  165. [1335736800000,33.55],
  166. [1335823200000,33.77],
  167. [1335909600000,33.76],
  168. [1335996000000,33.32],
  169. [1336082400000,32.61],
  170. [1336341600000,32.52],
  171. [1336428000000,32.67],
  172. [1336514400000,32.52],
  173. [1336600800000,31.92],
  174. [1336687200000,32.20],
  175. [1336946400000,32.23],
  176. [1337032800000,32.33],
  177. [1337119200000,32.36],
  178. [1337205600000,32.01],
  179. [1337292000000,31.31],
  180. [1337551200000,32.01],
  181. [1337637600000,32.01],
  182. [1337724000000,32.18],
  183. [1337810400000,31.54],
  184. [1337896800000,31.60],
  185. [1338242400000,32.05],
  186. [1338328800000,31.29],
  187. [1338415200000,31.05],
  188. [1338501600000,29.82],
  189. [1338760800000,30.31],
  190. [1338847200000,30.70],
  191. [1338933600000,31.69],
  192. [1339020000000,31.32],
  193. [1339106400000,31.65],
  194. [1339365600000,31.13],
  195. [1339452000000,31.77],
  196. [1339538400000,31.79],
  197. [1339624800000,31.67],
  198. [1339711200000,32.39],
  199. [1339970400000,32.63],
  200. [1340056800000,32.89],
  201. [1340143200000,31.99],
  202. [1340229600000,31.23],
  203. [1340316000000,31.57],
  204. [1340575200000,30.84],
  205. [1340661600000,31.07],
  206. [1340748000000,31.41],
  207. [1340834400000,31.17],
  208. [1340920800000,32.37],
  209. [1341180000000,32.19],
  210. [1341266400000,32.51],
  211. [1341439200000,32.53],
  212. [1341525600000,31.37],
  213. [1341784800000,30.43],
  214. [1341871200000,30.44],
  215. [1341957600000,30.20],
  216. [1342044000000,30.14],
  217. [1342130400000,30.65],
  218. [1342389600000,30.40],
  219. [1342476000000,30.65],
  220. [1342562400000,31.43],
  221. [1342648800000,31.89],
  222. [1342735200000,31.38],
  223. [1342994400000,30.64],
  224. [1343080800000,30.02],
  225. [1343167200000,30.33],
  226. [1343253600000,30.95],
  227. [1343340000000,31.89],
  228. [1343599200000,31.01],
  229. [1343685600000,30.88],
  230. [1343772000000,30.69],
  231. [1343858400000,30.58],
  232. [1343944800000,32.02],
  233. [1344204000000,32.14],
  234. [1344290400000,32.37],
  235. [1344376800000,32.51],
  236. [1344463200000,32.65],
  237. [1344549600000,32.64],
  238. [1344808800000,32.27],
  239. [1344895200000,32.10],
  240. [1344981600000,32.91],
  241. [1345068000000,33.65],
  242. [1345154400000,33.80],
  243. [1345413600000,33.92],
  244. [1345500000000,33.75],
  245. [1345586400000,33.84],
  246. [1345672800000,33.50],
  247. [1345759200000,32.26],
  248. [1346018400000,32.32],
  249. [1346104800000,32.06],
  250. [1346191200000,31.96],
  251. [1346277600000,31.46],
  252. [1346364000000,31.27],
  253. [1346709600000,31.43],
  254. [1346796000000,32.26],
  255. [1346882400000,32.79],
  256. [1346968800000,32.46],
  257. [1347228000000,32.13],
  258. [1347314400000,32.43],
  259. [1347400800000,32.42],
  260. [1347487200000,32.81],
  261. [1347573600000,33.34],
  262. [1347832800000,33.41],
  263. [1347919200000,32.57],
  264. [1348005600000,33.12],
  265. [1348092000000,34.53],
  266. [1348178400000,33.83],
  267. [1348437600000,33.41],
  268. [1348524000000,32.90],
  269. [1348610400000,32.53],
  270. [1348696800000,32.80],
  271. [1348783200000,32.44],
  272. [1349042400000,32.62],
  273. [1349128800000,32.57],
  274. [1349215200000,32.60],
  275. [1349301600000,32.68],
  276. [1349388000000,32.47],
  277. [1349647200000,32.23],
  278. [1349733600000,31.68],
  279. [1349820000000,31.51],
  280. [1349906400000,31.78],
  281. [1349992800000,31.94],
  282. [1350252000000,32.33],
  283. [1350338400000,33.24],
  284. [1350424800000,33.44],
  285. [1350511200000,33.48],
  286. [1350597600000,33.24],
  287. [1350856800000,33.49],
  288. [1350943200000,33.31],
  289. [1351029600000,33.36],
  290. [1351116000000,33.40],
  291. [1351202400000,34.01],
  292. [1351638000000,34.02],
  293. [1351724400000,34.36],
  294. [1351810800000,34.39],
  295. [1352070000000,34.24],
  296. [1352156400000,34.39],
  297. [1352242800000,33.47],
  298. [1352329200000,32.98],
  299. [1352415600000,32.90],
  300. [1352674800000,32.70],
  301. [1352761200000,32.54],
  302. [1352847600000,32.23],
  303. [1352934000000,32.64],
  304. [1353020400000,32.65],
  305. [1353279600000,32.92],
  306. [1353366000000,32.64],
  307. [1353452400000,32.84],
  308. [1353625200000,33.40],
  309. [1353884400000,33.30],
  310. [1353970800000,33.18],
  311. [1354057200000,33.88],
  312. [1354143600000,34.09],
  313. [1354230000000,34.61],
  314. [1354489200000,34.70],
  315. [1354575600000,35.30],
  316. [1354662000000,35.40],
  317. [1354748400000,35.14],
  318. [1354834800000,35.48],
  319. [1355094000000,35.75],
  320. [1355180400000,35.54],
  321. [1355266800000,35.96],
  322. [1355353200000,35.53],
  323. [1355439600000,37.56],
  324. [1355698800000,37.42],
  325. [1355785200000,37.49],
  326. [1355871600000,38.09],
  327. [1355958000000,37.87],
  328. [1356044400000,37.71],
  329. [1356303600000,37.53],
  330. [1356476400000,37.55],
  331. [1356562800000,37.30],
  332. [1356649200000,36.90],
  333. [1356908400000,37.68],
  334. [1357081200000,38.34],
  335. [1357167600000,37.75],
  336. [1357254000000,38.13],
  337. [1357513200000,37.94],
  338. [1357599600000,38.14],
  339. [1357686000000,38.66],
  340. [1357772400000,38.62],
  341. [1357858800000,38.09],
  342. [1358118000000,38.16],
  343. [1358204400000,38.15],
  344. [1358290800000,37.88],
  345. [1358377200000,37.73],
  346. [1358463600000,37.98],
  347. [1358809200000,37.95],
  348. [1358895600000,38.25],
  349. [1358982000000,38.10],
  350. [1359068400000,38.32],
  351. [1359327600000,38.24],
  352. [1359414000000,38.52],
  353. [1359500400000,37.94],
  354. [1359586800000,37.83],
  355. [1359673200000,38.34],
  356. [1359932400000,38.10],
  357. [1360018800000,38.51],
  358. [1360105200000,38.40],
  359. [1360191600000,38.07],
  360. [1360278000000,39.12],
  361. [1360537200000,38.64],
  362. [1360623600000,38.89],
  363. [1360710000000,38.81],
  364. [1360796400000,38.61],
  365. [1360882800000,38.63],
  366. [1361228400000,38.99],
  367. [1361314800000,38.77],
  368. [1361401200000,38.34],
  369. [1361487600000,38.55],
  370. [1361746800000,38.11],
  371. [1361833200000,38.59],
  372. [1361919600000,39.60],
  373. ]
  374. }],
  375. options: {
  376. chart: {
  377. id: 'area-datetime',
  378. type: 'area',
  379. height: 350,
  380. zoom: {
  381. autoScaleYaxis: true
  382. }
  383. },
  384. annotations: {
  385. yaxis: [{
  386. y: 30,
  387. borderColor: '#999',
  388. label: {
  389. show: true,
  390. text: 'Support',
  391. style: {
  392. color: "#fff",
  393. background: '#00E396'
  394. }
  395. }
  396. }],
  397. xaxis: [{
  398. x: new Date('14 Nov 2012').getTime(),
  399. borderColor: '#999',
  400. yAxisIndex: 0,
  401. label: {
  402. show: true,
  403. text: 'Rally',
  404. style: {
  405. color: "#fff",
  406. background: '#775DD0'
  407. }
  408. }
  409. }]
  410. },
  411. dataLabels: {
  412. enabled: false
  413. },
  414. markers: {
  415. size: 0,
  416. style: 'hollow',
  417. },
  418. xaxis: {
  419. type: 'datetime',
  420. min: new Date('01 Mar 2012').getTime(),
  421. tickAmount: 6,
  422. },
  423. tooltip: {
  424. x: {
  425. format: 'dd MMM yyyy'
  426. }
  427. },
  428. fill: {
  429. type: 'gradient',
  430. gradient: {
  431. shadeIntensity: 1,
  432. opacityFrom: 0.7,
  433. opacityTo: 0.9,
  434. stops: [0, 100]
  435. }
  436. },
  437. },
  438. selection: 'one_year',
  439. };
  440. }
  441. updateData(timeline) {
  442. this.setState({
  443. selection: timeline
  444. })
  445. switch (timeline) {
  446. case 'one_month':
  447. ApexCharts.exec(
  448. 'area-datetime',
  449. 'zoomX',
  450. new Date('28 Jan 2013').getTime(),
  451. new Date('27 Feb 2013').getTime()
  452. )
  453. break
  454. case 'six_months':
  455. ApexCharts.exec(
  456. 'area-datetime',
  457. 'zoomX',
  458. new Date('27 Sep 2012').getTime(),
  459. new Date('27 Feb 2013').getTime()
  460. )
  461. break
  462. case 'one_year':
  463. ApexCharts.exec(
  464. 'area-datetime',
  465. 'zoomX',
  466. new Date('27 Feb 2012').getTime(),
  467. new Date('27 Feb 2013').getTime()
  468. )
  469. break
  470. case 'ytd':
  471. ApexCharts.exec(
  472. 'area-datetime',
  473. 'zoomX',
  474. new Date('01 Jan 2013').getTime(),
  475. new Date('27 Feb 2013').getTime()
  476. )
  477. break
  478. case 'all':
  479. ApexCharts.exec(
  480. 'area-datetime',
  481. 'zoomX',
  482. new Date('23 Jan 2012').getTime(),
  483. new Date('27 Feb 2013').getTime()
  484. )
  485. break
  486. default:
  487. }
  488. }
  489. render() {
  490. return (
  491. <div>
  492. <div id="chart">
  493. <div class="toolbar">
  494. <button id="one_month"
  495. onClick={()=>this.updateData('one_month')} className={ (this.state.selection==='one_month' ? 'active' : '')}>
  496. 1M
  497. </button>
  498. &nbsp;
  499. <button id="six_months"
  500. onClick={()=>this.updateData('six_months')} className={ (this.state.selection==='six_months' ? 'active' : '')}>
  501. 6M
  502. </button>
  503. &nbsp;
  504. <button id="one_year"
  505. onClick={()=>this.updateData('one_year')} className={ (this.state.selection==='one_year' ? 'active' : '')}>
  506. 1Y
  507. </button>
  508. &nbsp;
  509. <button id="ytd"
  510. onClick={()=>this.updateData('ytd')} className={ (this.state.selection==='ytd' ? 'active' : '')}>
  511. YTD
  512. </button>
  513. &nbsp;
  514. <button id="all"
  515. onClick={()=>this.updateData('all')} className={ (this.state.selection==='all' ? 'active' : '')}>
  516. ALL
  517. </button>
  518. </div>
  519. <div id="chart-timeline">
  520. <ReactApexChart options={this.state.options} series={this.state.series} type="area" height={350} />
  521. </div>
  522. </div>
  523. <div id="html-dist"></div>
  524. </div>
  525. );
  526. }
  527. }
  528. const domContainer = document.querySelector('#app');
  529. ReactDOM.render(React.createElement(ApexChart), domContainer);
  530. </script>
  531. </body>
  532. </html>