This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

chartist to display nice pie...
#33
(02.05.2024, 10:39)admin Wrote: Click "Show code" under the example and it will show the relevant code.


I tried like that, but I don't have the color in front of the legend like in the example


Code:
$(function() {
  var chart;

  grp.listen('32/1/22', function(obj, type) {
    var planid = 12;
    var groups = ['32/2/19','32/2/21', '32/2/23','32/2/25','32/2/27','32/2/29','32/2/31','32/2/33','32/2/35','32/2/37','32/2/39','32/2/41'];

    var labels = [];
    var series = [];

    for (var group of groups) {
      var obj = grp.find(group);
      console.log(group, obj);
      labels.push(obj.name);
      series.push(obj.value);
    }

    var data = {
      labels: labels,
      series: series
    };

    var options = {
      width: '300px',
      height: '300px',
      donut: true,
      donutWidth: 50,
      donutSolid: true,
      startAngle: 270,
      showLabel: false
    };

    if (chart) {
      chart.update(data);
    } else {
      var el = $('<div class="chart"></div>').css({
        position: 'absolute',
        top: '750px',
        left: '1210px'
      }).appendTo('#plan-' + planid);

      chart = new Chartist.Pie('.chart', data, options);

      // Ajout des légendes
      var legendContainer = $('<div class="legend"></div>'); // Création du conteneur de légende
      data.labels.forEach(function(label, index) {
        legendContainer.append('<div><span class="dot" style="background-color: ' + chart.data.series[index].meta + '"></span>' + label + '</div>'); // Ajout de chaque élément de légende avec la couleur associée
      });
      el.append(legendContainer); // Ajout du conteneur de légende au graphique
    }
  }, true);
});
Reply


Messages In This Thread
chartist to display nice pie... - by domotiqa - 05.01.2022, 08:56
RE: chartist to display nice pie... - by jmir - 14.02.2022, 11:32
RE: chartist to display nice pie... - by jmir - 14.02.2022, 13:34
RE: chartist to display nice pie... - by jmir - 15.02.2022, 11:15
RE: chartist to display nice pie... - by Acla - 12.06.2023, 05:05
RE: chartist to display nice pie... - by JRP - 08.09.2022, 16:18
RE: chartist to display nice pie... - by Acla - 12.06.2023, 15:44
RE: chartist to display nice pie... - by jmir - 25.03.2024, 14:49
RE: chartist to display nice pie... - by hocine - 03.05.2024, 06:37

Forum Jump: