Chart.js documetation

https://www.chartjs.org/docs/latest/charts/doughnut.html#styling

 

Javascript

https://stackoverflow.com/questions/25594478/different-color-for-each-bar-in-a-bar-chart-chartjs

function getRandomColor() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

 

https://stackoverflow.com/questions/52098989/how-to-put-dynamic-colors-for-pie-chart-chart-js

// Step 1
colors=[];

// Step 2
for(let i=0;i<this.data.length;i++){
      this.colors.push('#'+Math.floor(Math.random()*16777215).toString(16));
}

// Stap 3
data: data,
backgroundColor: this.colors
.....

 

 

+ Recent posts