ui2022/chart--donut.html.twig line 1

Open in your IDE?
  1. {% set html_id = 'chart-%s'|format(token()) %}
  2. {% set dataset = _args.dataset %}
  3. {% set legend = _args.legend %}
  4. {% set label = _args.label|default('Total') %}
  5. <div class="dashboard__donutchart">
  6.     <div class="chart__donut chart-container" style="width:210px; height:210px; max-width:100%;">
  7.         <canvas id="{{ html_id }}"></canvas>
  8.     </div>
  9.     <div class="chart__overlay">
  10.         <span class="h1 mb-0 text-medium">{{- dataset|array_values|array_sum|number_format -}}</span>
  11.         <span class="font-14 text-semibold">{{ label }}</span>
  12.     </div>
  13. </div>
  14. <script type="text/javascript">
  15.     (function (window, document, $, undefined) {
  16.         $(function () {
  17.             var ctx = document.getElementById('{{ html_id }}').getContext('2d');
  18.             var cht = new Chart(ctx, {
  19.                 type: 'doughnut',
  20.                 data: {
  21.                     datasets: [{
  22.                         data: {{ dataset|array_values|json_encode|raw }},
  23.                         backgroundColor: {{ legend|map(l => l.color)|array_values|json_encode|raw }}
  24.                     }],
  25.                     labels: {{ legend|map(l => l.label)|array_values|json_encode|raw }}
  26.                 },
  27.                 options: {
  28.                     animation: false,
  29.                     responsive: true,
  30.                     rotation: 0,
  31.                     cutout: '65%',
  32.                     plugins: {
  33.                         legend: {
  34.                             display: false,
  35.                             reverse: true
  36.                         },
  37.                     }
  38.                 }
  39.             });
  40.         });
  41.     })(window, document, jQuery);
  42. </script>