Chartjs-How to assign different background colors to chart.js pie chart data set?

2👍

You can pass an array of strings (colours) to backgroundColor:

backgroundColor: ['red', 'green', 'blue']

Example:

new Chart(document.getElementById("chart"), {
  type: "pie",
  data: {
    datasets: [{
      data: [1, 2, 3],
      backgroundColor: ['red', 'green', 'blue']
    }]
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
<canvas id="chart"></canvas>

Leave a comment