{% set html_id = 'chart-%s'|format(token()) %}
{% set dataset = _args.dataset %}
{% set legend = _args.legend %}
{% set label = _args.label|default('Total') %}
<div class="dashboard__donutchart">
<div class="chart__donut chart-container" style="width:210px; height:210px; max-width:100%;">
<canvas id="{{ html_id }}"></canvas>
</div>
<div class="chart__overlay">
<span class="h1 mb-0 text-medium">{{- dataset|array_values|array_sum|number_format -}}</span>
<span class="font-14 text-semibold">{{ label }}</span>
</div>
</div>
<script type="text/javascript">
(function (window, document, $, undefined) {
$(function () {
var ctx = document.getElementById('{{ html_id }}').getContext('2d');
var cht = new Chart(ctx, {
type: 'doughnut',
data: {
datasets: [{
data: {{ dataset|array_values|json_encode|raw }},
backgroundColor: {{ legend|map(l => l.color)|array_values|json_encode|raw }}
}],
labels: {{ legend|map(l => l.label)|array_values|json_encode|raw }}
},
options: {
animation: false,
responsive: true,
rotation: 0,
cutout: '65%',
plugins: {
legend: {
display: false,
reverse: true
},
}
}
});
});
})(window, document, jQuery);
</script>