1

I have a database, and data is taken from it on request. How to set backgroundColor: rgb(144,204,244) if I don't know the number of sectors in the pie chart and it depends on the DB query. In the example on the official website, backgroundColor: rgb(144,204,244) is set 3 times because there are 3 sectors in the pie chart, but I have a different number of sectors in the pie chart.

var ctx = document.getElementById("doughnut").getContext("2d");
var chart = new Chart(ctx, {
  type: 'doughnut',
  data: {
    labels: expirationdates,
    datasets: [{
      label: 'Оплата парковочных пространств',
      backgroundColor: 'rgb(144,204,244)',
      borderColor: 'rgb(144,204,244)',
      data: prices,
    }]
  },
  options: {}
});

enter image description here

How do I set the color of the sectors if I don't know the number of these sectors in the pie chart? I read the official documentation and there the color is specified for each sector separately.

Bart Krakowski
  • 1,655
  • 2
  • 8
  • 25
Иван
  • 15
  • 4

0 Answers0