123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- {% assign data = charts[include.chart-id] %}
- {% assign id = include.id | default: include.chart-id %}
- {% assign height = include.height | default: data.height | default: 10 %}
- {% assign class = include.class %}
- {% if include['size'] == 'sm' %}
- {% assign class = class | append: ' chart-sm' | strip %}
- {% assign height = 2.5 %}
- {% elsif include['size'] == 'lg' %}
- {% assign class = class | append: ' chart-lg' | strip %}
- {% assign height = 15 %}
- {% endif %}
- {% if data %}
- {% if data.extend %}
- {% assign data = charts[data.extend] | concat_objects: charts[include.chart-id] %}
- {% endif %}
- <div id="chart-{{ id }}"{% if class %} class="{{ class }}"{% endif %}></div>
- {% capture script %}
- {% assign chart-type = data.type | default: 'bar' %}
- <script>
- // @formatter:off
- document.addEventListener("DOMContentLoaded", function () {
- {% if env == 'development' %}
- window.tabler_chart = window.tabler_chart || {};
- {% endif %}
- window.ApexCharts && ({% if env == 'development' %}window.tabler_chart["chart-{{ include.chart-id }}"] = {% endif %}new ApexCharts(document.getElementById('chart-{{ id }}'), {
- chart: {
- type: "{{ chart-type }}",
- fontFamily: 'inherit',
- height: {{ height | times: 16 }},
- {% if data.sparkline %}
- sparkline: {
- enabled: true
- },
- {% else %}
- parentHeightOffset: 0,
- toolbar: {
- show: false,
- },
- {% endif %}
- {% unless data.animations %}
- animations: {
- enabled: false
- },
- {% endunless %}
- {% if data.stacked %}
- stacked: true,
- {% endif %}
- },
- {% if chart-type == 'bar' %}
- plotOptions: {
- bar: {
- {% if data.horizontal %}
- barHeight: '50%',
- horizontal: true,
- {% else %}
- columnWidth: '50%',
- {% endif %}
- }
- },
- {% endif %}
- {% if chart-type == 'radialBar' %}
- plotOptions: {
- radialBar: {
- dataLabels: {
- total: {
- show: true,
- label: 'Totals',
- formatter: function (val) {
- return "44%";
- },
- },
- },
- },
- },
- {% endif %}
- {% if chart-type == 'bar' or chart-type == 'area' %}
- dataLabels: {
- enabled: {% if data.datalabels %}true{% else %}false{% endif %},
- },
- {% endif %}
- fill: {
- opacity: {% if chart-type == 'area' %}.16{% else %}1{% endif %},
- {% if chart-type == 'area' %}type: 'solid'{% endif %}
- },
- {% if data.title %}
- title: {
- text: "{{ data.title | escape }}",
- margin: 0,
- floating: true,
- offsetX: 10,
- style: {
- fontSize: '18px',
- },
- },
- {% endif %}
- {% if chart-type == 'area' or chart-type == 'line' %}
- stroke: {
- width: {% if data.stroke-width %}[{{ data.stroke-width | join: ', '}}]{% else %}2{% endif %},
- {% if data.stroke-dash %}dashArray: [{{ data.stroke-dash | join: ', '}}],{% endif %}
- lineCap: "round",
- curve: "{{ data.stroke-curve | default: 'smooth' }}",
- },
- {% endif %}
- {% if data.series %}
- {% if chart-type == 'pie' or chart-type == 'donut' or chart-type == 'radialBar' %}
- series: [{% for serie in data.series %}{{ serie.data }}{% unless forloop.last %}, {% endunless %}{% endfor %}],
- labels: [{% for serie in data.series %}"{{ serie.name }}"{% unless forloop.last %}, {% endunless %}{% endfor %}],
- {% else %}series: [{% for serie in data.series %}{
- name: "{{ serie.name }}",
- data: [{{ serie.data | join: ', ' }}]
- }{% unless forloop.last %},{% endunless %}{% endfor %}],
- {% endif %}
- {% endif %}
- tooltip: {
- theme: 'dark'
- },
- grid: {
- {% unless data.sparkline %}
- padding: {
- top: -20,
- right: 0,
- left: -4,
- bottom: -4
- },
- {% endunless %}
- {% if data.hide-grid %}
- show: false,
- {% else %}
- strokeDashArray: 4,
- {% if data.show-x %}
- xaxis: {
- lines: {
- show: true
- }
- },
- {% endif %}
- {% endif %}
- },
- {% if data.show-data-labels %}
- dataLabels: {
- enabled: true,
- },
- {% endif %}
- {% if data.categories or data.datetime %}
- xaxis: {
- labels: {
- padding: 0,
- {% if data.x-formatter %}
- formatter: function(val) {
- return {{ data.x-formatter }}
- },
- {% endif %}
- },
- tooltip: {
- enabled: false
- },
- {% if chart-type == 'area' or chart-type == 'bar' %}
- axisBorder: {
- show: false,
- },
- {% endif %}
- {% if data.categories %}
- categories: [{% for category in data.categories %}'{{ category }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
- {% endif %}
- {% if data.datetime %}
- type: 'datetime',
- {% endif %}
- },
- {% endif %}
- {% unless chart-type == 'pie' or chart-type == 'donut' or chart-type == 'radialBar' %}
- yaxis: {
- labels: {
- padding: 4
- },
- {% if data.y-max %}
- max: {{ data.y-max }},
- {% endif %}
- {% if data.y-title %}
- title: {
- text: '{{ data.y-title | escape }}'
- }
- {% endif %}
- },
- {% endunless %}
- {% if data.datetime %}
- {% assign date = data.start-date | default: '2020-06-20' | date: "%s" %}
- {% assign days-count = data.series[0].data.size %}
- labels: [
- {% for i in (1..days-count) %}{% assign date = date | plus: 86400 %}'{{ date | timestamp_to_date }}'{% unless forloop.last %}, {% endunless %}{% endfor %}
- ],
- {% endif %}
- {% if data.series %}
- colors: [{% for serie in data.series %}{% assign color = serie.color | default: data.color | default: 'primary' %}tabler.getColor("{{ color }}"{% if serie.color-opacity %}, {{ serie.color-opacity }}{% endif %}){% unless forloop.last %}, {% endunless %}{% endfor %}],
- {% endif %}
- legend: {
- {% if data.legend %}
- show: true,
- position: 'bottom',
- offsetY: 12,
- markers: {
- width: 10,
- height: 10,
- radius: 100,
- },
- itemMargin: {
- horizontal: 8,
- vertical: 8
- },
- {% else %}
- show: false,
- {% endif %}
- },
- {% if data.hide-tooltip or chart-type == 'pie' or chart-type == 'donut' %}
- tooltip: {
- {% if data.hide-tooltip %}
- enabled: false,
- {% endif %}
- {% if chart-type == 'pie' or chart-type == 'donut' %}
- fillSeriesColor: false
- {% endif %}
- },
- {% endif %}
- {% if data.hide-points %}
- point: {
- show: false
- },
- {% endif %}
- {% if data.show-markers %}
- markers: {
- size: 2
- },
- {% endif %}
- })).render();
- });
- // @formatter:on
- </script>
- {% endcapture %}
- {{ script }}
- {% endif %}
|