chart-sparkline.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {% assign type = include.type | default: 'bar' %}
  2. {% assign id = include.id %}
  3. {% assign color = include.color | default: 'blue' %}
  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. {% comment %}
  15. {% capture_global scripts %}
  16. <script>
  17. // @formatter:off
  18. document.addEventListener("DOMContentLoaded", function () {
  19. {% if env == 'development' %}
  20. window.tabler_chart = window.tabler_chart || {};
  21. {% endif %}
  22. window.ApexCharts && ({% if env == 'development' %}window.tabler_chart["sparkline-{{ id }}"] = {% endif %}new ApexCharts(document.getElementById('sparkline-{{ id }}'), {
  23. chart: {
  24. type: "{% if type == 'donut' %}radialBar{% else %}{{ type }}{% endif %}",
  25. fontFamily: 'inherit',
  26. height: {{ height | times: 16 | round }},
  27. {% if type == 'pie' or type == 'donut' %}
  28. width: {{ height | times: 16 | round }},
  29. {% endif %}
  30. animations: {
  31. enabled: false
  32. },
  33. sparkline: {
  34. enabled: true
  35. },
  36. },
  37. tooltip: {
  38. enabled: false,
  39. },
  40. {% if type == 'donut' %}
  41. plotOptions: {
  42. radialBar: {
  43. hollow: {
  44. margin: 0,
  45. size: '75%'
  46. },
  47. track: {
  48. margin: 0
  49. },
  50. dataLabels: {
  51. show: false
  52. }
  53. }
  54. },
  55. {% endif %}
  56. {% if type == 'area' %}
  57. fill: {
  58. gradient: {
  59. opacityFrom: [.1, .1]
  60. }
  61. },
  62. {% endif %}
  63. {% if type == 'area' or type == 'line' %}
  64. stroke: {
  65. width: 2,
  66. lineCap: "round",
  67. },
  68. {% endif %}
  69. {% if type == 'donut' %}
  70. colors: [tabler.getColor("{{ color | default: 'primary' }}")],
  71. series: [{{ data }}],
  72. {% else %}
  73. series: [{
  74. color: tabler.getColor("{{ color | default: 'primary' }}"),
  75. data: [{{ data }}]
  76. }],
  77. {% endif %}
  78. })).render();
  79. });
  80. // @formatter:on
  81. </script>
  82. {% endcapture_global %}
  83. {% endcomment %}
  84. {% endif %}