charts.mdx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. ---
  2. title: Charts
  3. libs: apexcharts
  4. summary: Tabler uses ApexCharts - a free and open-source modern charting library that helps developers to create beautiful and interactive visualizations for web pages.
  5. description: Interactive data visualizations with ApexCharts.
  6. ---
  7. To be able to use the charts in your application you will need to install the apexcharts dependency with `npm install apexcharts`.
  8. See also the [ApexCharts](https://apexcharts.com/) documentation.
  9. ## Line Chart
  10. Line charts are a typical pictorial representation that depicts trends and behaviors over time.
  11. ```html example centered columns={2} height="25rem"
  12. <div class="card">
  13. <div class="card-body">
  14. <div id="chart-demo-line" class="chart-lg"></div>
  15. </div>
  16. </div>
  17. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  18. <script>
  19. document.addEventListener("DOMContentLoaded", function() {
  20. window.ApexCharts && (new ApexCharts(document.getElementById('chart-demo-line'), {
  21. chart: {
  22. type: "line",
  23. fontFamily: 'inherit',
  24. height: 240,
  25. parentHeightOffset: 0,
  26. toolbar: {
  27. show: false,
  28. },
  29. animations: {
  30. enabled: false
  31. },
  32. },
  33. fill: {
  34. opacity: 1,
  35. },
  36. stroke: {
  37. width: 2,
  38. lineCap: "round",
  39. curve: "straight",
  40. },
  41. series: [{
  42. name: "Session Duration",
  43. data: [117, 92, 94, 98, 75, 110, 69, 80, 109, 113, 115, 95]
  44. }, {
  45. name: "Page Views",
  46. data: [59, 80, 61, 66, 70, 84, 87, 64, 94, 56, 55, 67]
  47. }, {
  48. name: "Total Visits",
  49. data: [53, 51, 52, 41, 46, 60, 45, 43, 30, 50, 58, 59]
  50. }],
  51. tooltip: {
  52. theme: 'dark'
  53. },
  54. grid: {
  55. padding: {
  56. top: -20,
  57. right: 0,
  58. left: -4,
  59. bottom: -4
  60. },
  61. strokeDashArray: 4,
  62. },
  63. xaxis: {
  64. labels: {
  65. padding: 0,
  66. },
  67. tooltip: {
  68. enabled: false
  69. },
  70. type: 'datetime',
  71. },
  72. yaxis: {
  73. labels: {
  74. padding: 4
  75. },
  76. },
  77. labels: [
  78. '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-24', '2020-06-25', '2020-06-26', '2020-06-27', '2020-06-28', '2020-06-29', '2020-06-30', '2020-07-01', '2020-07-02'
  79. ],
  80. colors: [tabler.getColor("yellow"), tabler.getColor("green"), tabler.getColor("primary")],
  81. legend: {
  82. show: true,
  83. position: 'bottom',
  84. offsetY: 12,
  85. markers: {
  86. width: 10,
  87. height: 10,
  88. radius: 100,
  89. },
  90. itemMargin: {
  91. horizontal: 8,
  92. vertical: 8
  93. },
  94. },
  95. })).render();
  96. });
  97. </script>
  98. ```
  99. ## Area Chart
  100. Area charts are used to represent quantitative variations.
  101. ```html example centered columns={2} height="25rem"
  102. <div class="card">
  103. <div class="card-body">
  104. <div id="chart-demo-area" class="chart-lg"></div>
  105. </div>
  106. </div>
  107. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  108. <script>
  109. document.addEventListener("DOMContentLoaded", function() {
  110. window.ApexCharts && (new ApexCharts(document.getElementById('chart-demo-area'), {
  111. chart: {
  112. type: "area",
  113. fontFamily: 'inherit',
  114. height: 240,
  115. parentHeightOffset: 0,
  116. toolbar: {
  117. show: false,
  118. },
  119. animations: {
  120. enabled: false
  121. },
  122. },
  123. dataLabels: {
  124. enabled: false,
  125. },
  126. fill: {
  127. opacity: .16,
  128. type: 'solid'
  129. },
  130. stroke: {
  131. width: 2,
  132. lineCap: "round",
  133. curve: "smooth",
  134. },
  135. series: [{
  136. name: "series1",
  137. data: [56, 40, 39, 47, 34, 48, 44]
  138. }, {
  139. name: "series2",
  140. data: [45, 43, 30, 23, 38, 39, 54]
  141. }],
  142. tooltip: {
  143. theme: 'dark'
  144. },
  145. grid: {
  146. padding: {
  147. top: -20,
  148. right: 0,
  149. left: -4,
  150. bottom: -4
  151. },
  152. strokeDashArray: 4,
  153. },
  154. xaxis: {
  155. labels: {
  156. padding: 0,
  157. },
  158. tooltip: {
  159. enabled: false
  160. },
  161. axisBorder: {
  162. show: false,
  163. },
  164. type: 'datetime',
  165. },
  166. yaxis: {
  167. labels: {
  168. padding: 4
  169. },
  170. },
  171. labels: [
  172. '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-24', '2020-06-25', '2020-06-26', '2020-06-27'
  173. ],
  174. colors: [tabler.getColor("primary"), tabler.getColor("purple")],
  175. legend: {
  176. show: true,
  177. position: 'bottom',
  178. offsetY: 12,
  179. markers: {
  180. width: 10,
  181. height: 10,
  182. radius: 100,
  183. },
  184. itemMargin: {
  185. horizontal: 8,
  186. vertical: 8
  187. },
  188. },
  189. })).render();
  190. });
  191. </script>
  192. ```
  193. ## Bar Chart
  194. A bar chart is the best tool for displaying comparisons between categories of data.
  195. ```html example centered columns={2} height="25rem"
  196. <div class="card">
  197. <div class="card-body">
  198. <div id="chart-demo-bar" class="chart-lg"></div>
  199. </div>
  200. </div>
  201. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  202. <script>
  203. document.addEventListener("DOMContentLoaded", function() {
  204. window.ApexCharts && (new ApexCharts(document.getElementById('chart-demo-bar'), {
  205. chart: {
  206. type: "bar",
  207. fontFamily: 'inherit',
  208. height: 240,
  209. parentHeightOffset: 0,
  210. toolbar: {
  211. show: false,
  212. },
  213. animations: {
  214. enabled: false
  215. },
  216. stacked: true,
  217. },
  218. plotOptions: {
  219. bar: {
  220. barHeight: '50%',
  221. horizontal: true,
  222. }
  223. },
  224. dataLabels: {
  225. enabled: false,
  226. },
  227. fill: {
  228. opacity: 1,
  229. },
  230. series: [{
  231. name: "Container for a Fanta",
  232. data: [44, 55, 41, 37, 22, 43, 21]
  233. }, {
  234. name: "Strange sunglasses",
  235. data: [53, 32, 33, 52, 13, 43, 32]
  236. }, {
  237. name: "Pen Pineapple Apple Pen",
  238. data: [12, 17, 11, 9, 15, 11, 20]
  239. }, {
  240. name: "Binoculars",
  241. data: [9, 7, 5, 8, 6, 9, 4]
  242. }, {
  243. name: "Magical notebook",
  244. data: [25, 12, 19, 32, 25, 24, 10]
  245. }],
  246. tooltip: {
  247. theme: 'dark'
  248. },
  249. grid: {
  250. padding: {
  251. top: -20,
  252. right: 0,
  253. left: -4,
  254. bottom: -4
  255. },
  256. strokeDashArray: 4,
  257. },
  258. xaxis: {
  259. labels: {
  260. padding: 0,
  261. formatter: function(val) {
  262. return val + "K"
  263. },
  264. },
  265. tooltip: {
  266. enabled: false
  267. },
  268. axisBorder: {
  269. show: false,
  270. },
  271. categories: ['2008', '2009', '2010', '2011', '2012', '2013', '2014'],
  272. },
  273. yaxis: {
  274. labels: {
  275. padding: 4
  276. },
  277. },
  278. colors: [tabler.getColor("purple"), tabler.getColor("green"), tabler.getColor("yellow"), tabler.getColor("red"), tabler.getColor("primary")],
  279. legend: {
  280. show: true,
  281. position: 'bottom',
  282. offsetY: 12,
  283. markers: {
  284. width: 10,
  285. height: 10,
  286. radius: 100,
  287. },
  288. itemMargin: {
  289. horizontal: 8,
  290. vertical: 8
  291. },
  292. },
  293. })).render();
  294. });
  295. </script>
  296. ```
  297. ## Pie Chart
  298. Pie charts are an instrumental visualization tool useful in expressing data and information in terms of percentages, ratio.
  299. ```html example centered columns={2} height="25rem"
  300. <div class="card">
  301. <div class="card-body">
  302. <div id="chart-demo-pie" class="chart-lg"></div>
  303. </div>
  304. </div>
  305. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  306. <script>
  307. document.addEventListener("DOMContentLoaded", function() {
  308. window.ApexCharts && (new ApexCharts(document.getElementById('chart-demo-pie'), {
  309. chart: {
  310. type: "donut",
  311. fontFamily: 'inherit',
  312. height: 240,
  313. sparkline: {
  314. enabled: true
  315. },
  316. animations: {
  317. enabled: false
  318. },
  319. },
  320. fill: {
  321. opacity: 1,
  322. },
  323. series: [44, 55, 12, 2],
  324. labels: ["Direct", "Affilliate", "E-mail", "Other"],
  325. tooltip: {
  326. theme: 'dark'
  327. },
  328. grid: {
  329. strokeDashArray: 4,
  330. },
  331. colors: [tabler.getColor("primary"), tabler.getColor("primary", 0.8), tabler.getColor("primary", 0.6), tabler.getColor("gray-300")],
  332. legend: {
  333. show: true,
  334. position: 'bottom',
  335. offsetY: 12,
  336. markers: {
  337. width: 10,
  338. height: 10,
  339. radius: 100,
  340. },
  341. itemMargin: {
  342. horizontal: 8,
  343. vertical: 8
  344. },
  345. },
  346. tooltip: {
  347. fillSeriesColor: false
  348. },
  349. })).render();
  350. });
  351. </script>
  352. ```
  353. ## Heatmap Chart
  354. Heatmap is a visualization tool that employs color the way a bar chart employs height and width in representing data.
  355. ```html example centered columns={2} height="25rem"
  356. <div class="card">
  357. <div class="card-body">
  358. <div id="chart-demo-pie" class="chart-lg"></div>
  359. </div>
  360. </div>
  361. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  362. <script>
  363. document.addEventListener("DOMContentLoaded", function() {
  364. window.ApexCharts && (new ApexCharts(document.getElementById('chart-demo-pie'), {
  365. chart: {
  366. type: "donut",
  367. fontFamily: 'inherit',
  368. height: 240,
  369. sparkline: {
  370. enabled: true
  371. },
  372. animations: {
  373. enabled: false
  374. },
  375. },
  376. fill: {
  377. opacity: 1,
  378. },
  379. series: [44, 55, 12, 2],
  380. labels: ["Direct", "Affilliate", "E-mail", "Other"],
  381. tooltip: {
  382. theme: 'dark'
  383. },
  384. grid: {
  385. strokeDashArray: 4,
  386. },
  387. colors: [tabler.getColor("primary"), tabler.getColor("primary", 0.8), tabler.getColor("primary", 0.6), tabler.getColor("gray-300")],
  388. legend: {
  389. show: true,
  390. position: 'bottom',
  391. offsetY: 12,
  392. markers: {
  393. width: 10,
  394. height: 10,
  395. radius: 100,
  396. },
  397. itemMargin: {
  398. horizontal: 8,
  399. vertical: 8
  400. },
  401. },
  402. tooltip: {
  403. fillSeriesColor: false
  404. },
  405. })).render();
  406. });
  407. </script>
  408. ```
  409. ## Advanced example
  410. ```html example centered columns={2} height="25rem"
  411. <div class="card">
  412. <div class="card-body">
  413. <div id="chart-social-referrals" class="chart-lg"></div>
  414. </div>
  415. </div>
  416. <script src="$TABLER_CDN/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
  417. <script>
  418. document.addEventListener("DOMContentLoaded", function() {
  419. window.ApexCharts && (new ApexCharts(document.getElementById('chart-social-referrals'), {
  420. chart: {
  421. type: "line",
  422. fontFamily: 'inherit',
  423. height: 240,
  424. parentHeightOffset: 0,
  425. toolbar: {
  426. show: false,
  427. },
  428. animations: {
  429. enabled: false
  430. },
  431. },
  432. fill: {
  433. opacity: 1,
  434. },
  435. stroke: {
  436. width: 2,
  437. lineCap: "round",
  438. curve: "smooth",
  439. },
  440. series: [{
  441. name: "Facebook",
  442. data: [13281, 8521, 15038, 9983, 15417, 8888, 7052, 14270, 5214, 9587, 5950, 16852, 17836, 12217, 17406, 12262, 9147, 14961, 18292, 15230, 13435, 10649, 5140, 13680, 4508, 13271, 13413, 5543, 18727, 18238, 18175, 6246, 5864, 17847, 9170, 6445, 12945, 8142, 8980, 10422, 15535, 11569, 10114, 17621, 16138, 13046, 6652, 9906, 14100, 16495, 6749]
  443. }, {
  444. name: "Twitter",
  445. data: [3680, 1862, 3070, 2252, 5348, 3091, 3000, 3984, 5176, 5325, 2420, 5474, 3098, 1893, 3748, 2879, 4197, 5186, 4213, 4334, 2807, 1594, 4863, 2030, 3752, 4856, 5341, 3954, 3461, 3097, 3404, 4949, 2283, 3227, 3630, 2360, 3477, 4675, 1901, 2252, 3347, 2954, 5029, 2079, 2830, 3292, 4578, 3401, 4104, 3749, 4457, 3734]
  446. }, {
  447. name: "Dribbble",
  448. data: [722, 1866, 961, 1108, 1110, 561, 1753, 1815, 1985, 776, 859, 547, 1488, 766, 702, 621, 1599, 1372, 1620, 963, 759, 764, 739, 789, 1696, 1454, 1842, 734, 551, 1689, 1924, 1875, 908, 1675, 1541, 1953, 534, 502, 1524, 1867, 719, 1472, 1608, 1025, 889, 1150, 654, 1695, 1662, 1285, 1787]
  449. }],
  450. tooltip: {
  451. theme: 'dark'
  452. },
  453. grid: {
  454. padding: {
  455. top: -20,
  456. right: 0,
  457. left: -4,
  458. bottom: -4
  459. },
  460. strokeDashArray: 4,
  461. xaxis: {
  462. lines: {
  463. show: true
  464. }
  465. },
  466. },
  467. xaxis: {
  468. labels: {
  469. padding: 0,
  470. },
  471. tooltip: {
  472. enabled: false
  473. },
  474. type: 'datetime',
  475. },
  476. yaxis: {
  477. labels: {
  478. padding: 4
  479. },
  480. },
  481. labels: [
  482. '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-24', '2020-06-25', '2020-06-26', '2020-06-27', '2020-06-28', '2020-06-29', '2020-06-30', '2020-07-01', '2020-07-02', '2020-07-03', '2020-07-04', '2020-07-05', '2020-07-06', '2020-07-07', '2020-07-08', '2020-07-09', '2020-07-10', '2020-07-11', '2020-07-12', '2020-07-13', '2020-07-14', '2020-07-15', '2020-07-16', '2020-07-17', '2020-07-18', '2020-07-19', '2020-07-20', '2020-07-21', '2020-07-22', '2020-07-23', '2020-07-24', '2020-07-25', '2020-07-26', '2020-07-27', '2020-07-28', '2020-07-29', '2020-07-30', '2020-07-31', '2020-08-01', '2020-08-02', '2020-08-03', '2020-08-04', '2020-08-05', '2020-08-06', '2020-08-07', '2020-08-08', '2020-08-09', '2020-08-10'
  483. ],
  484. colors: [tabler.getColor("facebook"), tabler.getColor("twitter"), tabler.getColor("dribbble")],
  485. legend: {
  486. show: true,
  487. position: 'bottom',
  488. offsetY: 12,
  489. markers: {
  490. width: 10,
  491. height: 10,
  492. radius: 100,
  493. },
  494. itemMargin: {
  495. horizontal: 8,
  496. vertical: 8
  497. },
  498. },
  499. })).render();
  500. });
  501. </script>
  502. ```