chart-sparkline.html 2.3 KB

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