chart-sparkline.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {% assign type = include.type | default: 'bar' %}
  2. {% assign id = include.id %}
  3. {% assign color = include.color | default: 'primary' %}
  4. {% assign height = include.height | default: 2.5 %}
  5. {% if include.small %}
  6. {% assign height = include.height | default: 1.5 %}
  7. {% endif %}
  8. {% assign data = include.data %}
  9. {% if include.percentage %}
  10. {% assign data = include.percentage %}
  11. {% endif %}
  12. {% if id %}
  13. <div class="chart-sparkline{% if type == 'pie' or type == 'donut' %} chart-sparkline-square{% endif %}{% if include.wide %} chart-sparkline-wide{% endif %}{% if include.small %} chart-sparkline-sm{% endif %}" id="sparkline-{{ id }}"></div>
  14. {% capture_script %}
  15. <script>
  16. document.addEventListener("DOMContentLoaded", function () {
  17. {% if environment == 'development' %}
  18. window.tabler_chart = window.tabler_chart || {};
  19. {% endif %}
  20. window.ApexCharts && ({% if environment == 'development' %}window.tabler_chart["sparkline-{{ id }}"] = {% endif %}new ApexCharts(document.getElementById('sparkline-{{ id }}'), {
  21. chart: {
  22. type: "{% if type == 'donut' %}radialBar{% else %}{{ type }}{% endif %}",
  23. fontFamily: 'inherit',
  24. height: {{ height | times: 16 | round }},
  25. {% if type == 'pie' or type == 'donut' %}
  26. width: {{ height | times: 16 | round }},
  27. {% endif %}
  28. animations: {
  29. enabled: false
  30. },
  31. sparkline: {
  32. enabled: true
  33. },
  34. },
  35. tooltip: {
  36. enabled: false,
  37. },
  38. {% if type == 'donut' %}
  39. plotOptions: {
  40. radialBar: {
  41. hollow: {
  42. margin: 0,
  43. size: '75%'
  44. },
  45. track: {
  46. margin: 0
  47. },
  48. dataLabels: {
  49. show: false
  50. }
  51. }
  52. },
  53. {% endif %}
  54. {% if type == 'area' %}
  55. fill: {
  56. gradient: {
  57. opacityFrom: [.1, .1]
  58. }
  59. },
  60. {% endif %}
  61. {% if type == 'area' or type == 'line' %}
  62. stroke: {
  63. width: 2,
  64. lineCap: "round",
  65. },
  66. {% endif %}
  67. {% if type == 'donut' %}
  68. colors: ['var(--tblr-{{ color }})'],
  69. series: [{{ data }}],
  70. {% else %}
  71. series: [{
  72. color: 'var(--tblr-{{ color }})',
  73. data: [{{ data }}]
  74. }],
  75. {% endif %}
  76. })).render();
  77. });
  78. </script>
  79. {% endcapture_script %}
  80. {% endif %}