sparklines.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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>Sparklines</title>
  8. <link href="../../assets/styles.css" rel="stylesheet" />
  9. <style>
  10. .row {
  11. overflow: hidden;
  12. max-width: 890px;
  13. margin: 30px auto;
  14. display: flex;
  15. }
  16. .col-md-4 {
  17. width: 33.33%;
  18. padding: 0 25px;
  19. }
  20. table {
  21. width: 100%;
  22. }
  23. tbody tr {
  24. border-top: 1px solid #e7e7e7;
  25. }
  26. th {
  27. font-weight: bold;
  28. font-family: Helvetica;
  29. padding-bottom: 20px;
  30. }
  31. td, th {
  32. width: 25%;
  33. text-align: center;
  34. height: 65px;
  35. }
  36. td div {
  37. margin: 0 auto;
  38. }
  39. .left {
  40. float: left;
  41. }
  42. .right {
  43. float: right;
  44. }
  45. @media only screen and (max-width: 480px) {
  46. th:first-child, td:first-child {
  47. display: none;
  48. }
  49. .row {
  50. display: block;
  51. }
  52. .col-md-4 {
  53. padding: 0;
  54. width: 100%;
  55. }
  56. }
  57. </style>
  58. <script>
  59. window.Promise ||
  60. document.write(
  61. '<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
  62. )
  63. window.Promise ||
  64. document.write(
  65. '<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
  66. )
  67. window.Promise ||
  68. document.write(
  69. '<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
  70. )
  71. </script>
  72. <script src="https://cdn.jsdelivr.net/npm/react@16.12/umd/react.production.min.js"></script>
  73. <script src="https://cdn.jsdelivr.net/npm/react-dom@16.12/umd/react-dom.production.min.js"></script>
  74. <script src="https://cdn.jsdelivr.net/npm/prop-types@15.7.2/prop-types.min.js"></script>
  75. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
  76. <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
  77. <script src="https://cdn.jsdelivr.net/npm/react-apexcharts@1.3.6/dist/react-apexcharts.iife.min.js"></script>
  78. <script>
  79. window.Apex = {
  80. stroke: {
  81. width: 3
  82. },
  83. markers: {
  84. size: 0
  85. },
  86. tooltip: {
  87. fixed: {
  88. enabled: true,
  89. }
  90. }
  91. };
  92. var randomizeArray = function (arg) {
  93. var array = arg.slice();
  94. var currentIndex = array.length,
  95. temporaryValue, randomIndex;
  96. while (0 !== currentIndex) {
  97. randomIndex = Math.floor(Math.random() * currentIndex);
  98. currentIndex -= 1;
  99. temporaryValue = array[currentIndex];
  100. array[currentIndex] = array[randomIndex];
  101. array[randomIndex] = temporaryValue;
  102. }
  103. return array;
  104. }
  105. // data for the sparklines that appear below header area
  106. var sparklineData = [47, 45, 54, 38, 56, 24, 65, 31, 37, 39, 62, 51, 35, 41, 35, 27, 93, 53, 61, 27, 54, 43, 19, 46];
  107. </script>
  108. </head>
  109. <body>
  110. <div id="app"></div>
  111. <div id="html">
  112. &lt;div&gt;
  113. &lt;div class=&quot;row&quot;&gt;
  114. &lt;div class=&quot;col-md-4&quot;&gt;
  115. &lt;div id=&quot;chart-spark1&quot;&gt;
  116. &lt;ReactApexChart options={this.state.options} series={this.state.series} type=&quot;area&quot; height={160} /&gt;
  117. &lt;/div&gt;
  118. &lt;/div&gt;
  119. &lt;div class=&quot;col-md-4&quot;&gt;
  120. &lt;div id=&quot;chart-spark2&quot;&gt;
  121. &lt;ReactApexChart options={this.state.optionsSpark2} series={this.state.seriesSpark2} type=&quot;area&quot; height={160} /&gt;
  122. &lt;/div&gt;
  123. &lt;/div&gt;
  124. &lt;div class=&quot;col-md-4&quot;&gt;
  125. &lt;div id=&quot;chart-spark3&quot;&gt;
  126. &lt;ReactApexChart options={this.state.optionsSpark3} series={this.state.seriesSpark3} type=&quot;area&quot; height={160} /&gt;
  127. &lt;/div&gt;
  128. &lt;/div&gt;
  129. &lt;/div&gt;
  130. &lt;div class=&quot;row&quot;&gt;
  131. &lt;table&gt;
  132. &lt;thead&gt;
  133. &lt;th&gt;Total Value&lt;/th&gt;
  134. &lt;th&gt;Percentage of Portfolio&lt;/th&gt;
  135. &lt;th&gt;Last 10 days&lt;/th&gt;
  136. &lt;th&gt;Volume&lt;/th&gt;
  137. &lt;/thead&gt;
  138. &lt;tbody&gt;
  139. &lt;tr&gt;
  140. &lt;td&gt;$32,554&lt;/td&gt;
  141. &lt;td&gt;15%&lt;/td&gt;
  142. &lt;td&gt;
  143. &lt;div id=&quot;chart-1&quot;&gt;
  144. &lt;ReactApexChart options={this.state.options1} series={this.state.series1} type=&quot;line&quot; height={35} width={100} /&gt;
  145. &lt;/div&gt;
  146. &lt;/td&gt;
  147. &lt;td&gt;
  148. &lt;div id=&quot;chart-5&quot;&gt;
  149. &lt;ReactApexChart options={this.state.options5} series={this.state.series5} type=&quot;bar&quot; height={35} width={100} /&gt;
  150. &lt;/div&gt;
  151. &lt;/td&gt;
  152. &lt;/tr&gt;
  153. &lt;tr&gt;
  154. &lt;td&gt;$23,533&lt;/td&gt;
  155. &lt;td&gt;7%&lt;/td&gt;
  156. &lt;td&gt;
  157. &lt;div id=&quot;chart-2&quot;&gt;
  158. &lt;ReactApexChart options={this.state.options2} series={this.state.series2} type=&quot;line&quot; height={35} width={100} /&gt;
  159. &lt;/div&gt;
  160. &lt;/td&gt;
  161. &lt;td&gt;
  162. &lt;div id=&quot;chart-6&quot;&gt;
  163. &lt;ReactApexChart options={this.state.options6} series={this.state.series6} type=&quot;bar&quot; height={35} width={100} /&gt;
  164. &lt;/div&gt;
  165. &lt;/td&gt;
  166. &lt;/tr&gt;
  167. &lt;tr&gt;
  168. &lt;td&gt;$54,276&lt;/td&gt;
  169. &lt;td&gt;9%&lt;/td&gt;
  170. &lt;td&gt;
  171. &lt;div id=&quot;chart-3&quot;&gt;
  172. &lt;ReactApexChart options={this.state.options3} series={this.state.series3} type=&quot;pie&quot; height={40} width={40} /&gt;
  173. &lt;/div&gt;
  174. &lt;/td&gt;
  175. &lt;td&gt;
  176. &lt;div id=&quot;chart-7&quot;&gt;
  177. &lt;ReactApexChart options={this.state.options7} series={this.state.series7} type=&quot;radialBar&quot; height={50} width={50} /&gt;
  178. &lt;/div&gt;
  179. &lt;/td&gt;
  180. &lt;/tr&gt;
  181. &lt;tr&gt;
  182. &lt;td&gt;$11,533&lt;/td&gt;
  183. &lt;td&gt;2%&lt;/td&gt;
  184. &lt;td&gt;
  185. &lt;div id=&quot;chart-4&quot;&gt;
  186. &lt;ReactApexChart options={this.state.options4} series={this.state.series4} type=&quot;donut&quot; height={40} width={40} /&gt;
  187. &lt;/div&gt;
  188. &lt;/td&gt;
  189. &lt;td&gt;
  190. &lt;div id=&quot;chart-8&quot;&gt;
  191. &lt;ReactApexChart options={this.state.options8} series={this.state.series8} type=&quot;radialBar&quot; height={40} width={40} /&gt;
  192. &lt;/div&gt;
  193. &lt;/td&gt;
  194. &lt;/tr&gt;
  195. &lt;/tbody&gt;
  196. &lt;/table&gt;
  197. &lt;/div&gt;
  198. &lt;/div&gt;
  199. </div>
  200. <script type="text/babel">
  201. class ApexChart extends React.Component {
  202. constructor(props) {
  203. super(props);
  204. this.state = {
  205. series: [{
  206. data: randomizeArray(sparklineData)
  207. }],
  208. options: {
  209. chart: {
  210. type: 'area',
  211. height: 160,
  212. sparkline: {
  213. enabled: true
  214. },
  215. },
  216. stroke: {
  217. curve: 'straight'
  218. },
  219. fill: {
  220. opacity: 0.3,
  221. },
  222. yaxis: {
  223. min: 0
  224. },
  225. colors: ['#DCE6EC'],
  226. title: {
  227. text: '$424,652',
  228. offsetX: 0,
  229. style: {
  230. fontSize: '24px',
  231. }
  232. },
  233. subtitle: {
  234. text: 'Sales',
  235. offsetX: 0,
  236. style: {
  237. fontSize: '14px',
  238. }
  239. }
  240. },
  241. seriesSpark2: [{
  242. data: randomizeArray(sparklineData)
  243. }],
  244. optionsSpark2: {
  245. chart: {
  246. type: 'area',
  247. height: 160,
  248. sparkline: {
  249. enabled: true
  250. },
  251. },
  252. stroke: {
  253. curve: 'straight'
  254. },
  255. fill: {
  256. opacity: 0.3,
  257. },
  258. yaxis: {
  259. min: 0
  260. },
  261. colors: ['#DCE6EC'],
  262. title: {
  263. text: '$235,312',
  264. offsetX: 0,
  265. style: {
  266. fontSize: '24px',
  267. }
  268. },
  269. subtitle: {
  270. text: 'Expenses',
  271. offsetX: 0,
  272. style: {
  273. fontSize: '14px',
  274. }
  275. }
  276. },
  277. seriesSpark3: [{
  278. data: randomizeArray(sparklineData)
  279. }],
  280. optionsSpark3: {
  281. chart: {
  282. type: 'area',
  283. height: 160,
  284. sparkline: {
  285. enabled: true
  286. },
  287. },
  288. stroke: {
  289. curve: 'straight'
  290. },
  291. fill: {
  292. opacity: 0.3
  293. },
  294. xaxis: {
  295. crosshairs: {
  296. width: 1
  297. },
  298. },
  299. yaxis: {
  300. min: 0
  301. },
  302. title: {
  303. text: '$135,965',
  304. offsetX: 0,
  305. style: {
  306. fontSize: '24px',
  307. }
  308. },
  309. subtitle: {
  310. text: 'Profits',
  311. offsetX: 0,
  312. style: {
  313. fontSize: '14px',
  314. }
  315. }
  316. },
  317. series1: [{
  318. data: [25, 66, 41, 89, 63, 25, 44, 12, 36, 9, 54]
  319. }],
  320. options1: {
  321. chart: {
  322. type: 'line',
  323. width: 100,
  324. height: 35,
  325. sparkline: {
  326. enabled: true
  327. }
  328. },
  329. tooltip: {
  330. fixed: {
  331. enabled: false
  332. },
  333. x: {
  334. show: false
  335. },
  336. y: {
  337. title: {
  338. formatter: function (seriesName) {
  339. return ''
  340. }
  341. }
  342. },
  343. marker: {
  344. show: false
  345. }
  346. }
  347. },
  348. series2: [{
  349. data: [12, 14, 2, 47, 42, 15, 47, 75, 65, 19, 14]
  350. }],
  351. options2: {
  352. chart: {
  353. type: 'line',
  354. width: 100,
  355. height: 35,
  356. sparkline: {
  357. enabled: true
  358. }
  359. },
  360. tooltip: {
  361. fixed: {
  362. enabled: false
  363. },
  364. x: {
  365. show: false
  366. },
  367. y: {
  368. title: {
  369. formatter: function (seriesName) {
  370. return ''
  371. }
  372. }
  373. },
  374. marker: {
  375. show: false
  376. }
  377. }
  378. },
  379. series3: [43, 32, 12, 9],
  380. options3: {
  381. chart: {
  382. type: 'pie',
  383. width: 40,
  384. height: 40,
  385. sparkline: {
  386. enabled: true
  387. }
  388. },
  389. stroke: {
  390. width: 1
  391. },
  392. tooltip: {
  393. fixed: {
  394. enabled: false
  395. },
  396. }
  397. },
  398. series4: [43, 32, 12, 9],
  399. options4: {
  400. chart: {
  401. type: 'donut',
  402. width: 40,
  403. height: 40,
  404. sparkline: {
  405. enabled: true
  406. }
  407. },
  408. stroke: {
  409. width: 1
  410. },
  411. tooltip: {
  412. fixed: {
  413. enabled: false
  414. },
  415. }
  416. },
  417. series5: [{
  418. data: [25, 66, 41, 89, 63, 25, 44, 12, 36, 9, 54]
  419. }],
  420. options5: {
  421. chart: {
  422. type: 'bar',
  423. width: 100,
  424. height: 35,
  425. sparkline: {
  426. enabled: true
  427. }
  428. },
  429. plotOptions: {
  430. bar: {
  431. columnWidth: '80%'
  432. }
  433. },
  434. labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  435. xaxis: {
  436. crosshairs: {
  437. width: 1
  438. },
  439. },
  440. tooltip: {
  441. fixed: {
  442. enabled: false
  443. },
  444. x: {
  445. show: false
  446. },
  447. y: {
  448. title: {
  449. formatter: function (seriesName) {
  450. return ''
  451. }
  452. }
  453. },
  454. marker: {
  455. show: false
  456. }
  457. }
  458. },
  459. series6: [{
  460. data: [12, 14, 2, 47, 42, 15, 47, 75, 65, 19, 14]
  461. }],
  462. options6: {
  463. chart: {
  464. type: 'bar',
  465. width: 100,
  466. height: 35,
  467. sparkline: {
  468. enabled: true
  469. }
  470. },
  471. plotOptions: {
  472. bar: {
  473. columnWidth: '80%'
  474. }
  475. },
  476. labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  477. xaxis: {
  478. crosshairs: {
  479. width: 1
  480. },
  481. },
  482. tooltip: {
  483. fixed: {
  484. enabled: false
  485. },
  486. x: {
  487. show: false
  488. },
  489. y: {
  490. title: {
  491. formatter: function (seriesName) {
  492. return ''
  493. }
  494. }
  495. },
  496. marker: {
  497. show: false
  498. }
  499. }
  500. },
  501. series7: [45],
  502. options7: {
  503. chart: {
  504. type: 'radialBar',
  505. width: 50,
  506. height: 50,
  507. sparkline: {
  508. enabled: true
  509. }
  510. },
  511. dataLabels: {
  512. enabled: false
  513. },
  514. plotOptions: {
  515. radialBar: {
  516. hollow: {
  517. margin: 0,
  518. size: '50%'
  519. },
  520. track: {
  521. margin: 0
  522. },
  523. dataLabels: {
  524. show: false
  525. }
  526. }
  527. }
  528. },
  529. series8: [53, 67],
  530. options8: {
  531. chart: {
  532. type: 'radialBar',
  533. width: 40,
  534. height: 40,
  535. sparkline: {
  536. enabled: true
  537. }
  538. },
  539. dataLabels: {
  540. enabled: false
  541. },
  542. plotOptions: {
  543. radialBar: {
  544. hollow: {
  545. margin: 0,
  546. size: '50%'
  547. },
  548. track: {
  549. margin: 1
  550. },
  551. dataLabels: {
  552. show: false
  553. }
  554. }
  555. }
  556. },
  557. };
  558. }
  559. render() {
  560. return (
  561. <div>
  562. <div>
  563. <div class="row">
  564. <div class="col-md-4">
  565. <div id="chart-spark1">
  566. <ReactApexChart options={this.state.options} series={this.state.series} type="area" height={160} />
  567. </div>
  568. </div>
  569. <div class="col-md-4">
  570. <div id="chart-spark2">
  571. <ReactApexChart options={this.state.optionsSpark2} series={this.state.seriesSpark2} type="area" height={160} />
  572. </div>
  573. </div>
  574. <div class="col-md-4">
  575. <div id="chart-spark3">
  576. <ReactApexChart options={this.state.optionsSpark3} series={this.state.seriesSpark3} type="area" height={160} />
  577. </div>
  578. </div>
  579. </div>
  580. <div class="row">
  581. <table>
  582. <thead>
  583. <th>Total Value</th>
  584. <th>Percentage of Portfolio</th>
  585. <th>Last 10 days</th>
  586. <th>Volume</th>
  587. </thead>
  588. <tbody>
  589. <tr>
  590. <td>$32,554</td>
  591. <td>15%</td>
  592. <td>
  593. <div id="chart-1">
  594. <ReactApexChart options={this.state.options1} series={this.state.series1} type="line" height={35} width={100} />
  595. </div>
  596. </td>
  597. <td>
  598. <div id="chart-5">
  599. <ReactApexChart options={this.state.options5} series={this.state.series5} type="bar" height={35} width={100} />
  600. </div>
  601. </td>
  602. </tr>
  603. <tr>
  604. <td>$23,533</td>
  605. <td>7%</td>
  606. <td>
  607. <div id="chart-2">
  608. <ReactApexChart options={this.state.options2} series={this.state.series2} type="line" height={35} width={100} />
  609. </div>
  610. </td>
  611. <td>
  612. <div id="chart-6">
  613. <ReactApexChart options={this.state.options6} series={this.state.series6} type="bar" height={35} width={100} />
  614. </div>
  615. </td>
  616. </tr>
  617. <tr>
  618. <td>$54,276</td>
  619. <td>9%</td>
  620. <td>
  621. <div id="chart-3">
  622. <ReactApexChart options={this.state.options3} series={this.state.series3} type="pie" height={40} width={40} />
  623. </div>
  624. </td>
  625. <td>
  626. <div id="chart-7">
  627. <ReactApexChart options={this.state.options7} series={this.state.series7} type="radialBar" height={50} width={50} />
  628. </div>
  629. </td>
  630. </tr>
  631. <tr>
  632. <td>$11,533</td>
  633. <td>2%</td>
  634. <td>
  635. <div id="chart-4">
  636. <ReactApexChart options={this.state.options4} series={this.state.series4} type="donut" height={40} width={40} />
  637. </div>
  638. </td>
  639. <td>
  640. <div id="chart-8">
  641. <ReactApexChart options={this.state.options8} series={this.state.series8} type="radialBar" height={40} width={40} />
  642. </div>
  643. </td>
  644. </tr>
  645. </tbody>
  646. </table>
  647. </div>
  648. </div>
  649. <div id="html-dist"></div>
  650. </div>
  651. );
  652. }
  653. }
  654. const domContainer = document.querySelector('#app');
  655. ReactDOM.render(React.createElement(ApexChart), domContainer);
  656. </script>
  657. </body>
  658. </html>