area-datetime.html 15 KB

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