score:5

Accepted answer

no, chartjs does not come with this option.

i guess you have two options:

  • if you know a maximum (ex: there won't be more than 10 values), then you can make an array with 10 colors and assign the first colors to the elements you have (ex: if you have 5 elements, assign the first 5 colors to them). you could easily randomize for example where in the array does the assignment start, to still get a different color set every time.

    this method if good if you want to keep your colors to match a specific color theme.

  • if you do not care about a color theme, i think the easiest would be to generate the colors randomly. with this function, you can only hope to not get twice the same color (very very unlikely):

function getrandomcolor() {
    var letters = '0123456789abcdef';
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[math.floor(math.random() * 16)];
    }
    return color;
}

console.log(getrandomcolor());


Related Query

More Query from same tag