charts.mdx 14 KB

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