[Chartjs]-Colour sets for Chart.js border colour

2👍

✅

Something like the following should do the trick :

var colorArray = [["#FF4000", false], ["#81BEF7", false], ["#5882FA", false], 
                 ["#04B404", false], ["#A901DB", false], ["#F5A9BC", false]];

// The following makes sure you don't use the same color twice for your datasets
var color;
while (true) {
    var test = colorArray[parseInt(Math.random() * 6)];
    if (!test[1]) {
        color = test[0];
        colorArray[colorArray.indexOf(test)][1] = true;
        break;
    }
}

newDataset = { 
    label: data[i].firstName+' '+data[i].lastName, 
    borderColor: color, 
    backgroundColor: "rgba(0,0,0,0)", 
    data: tmpscore, 
}; 

You basically create an array of the colors you want (which fit your style) and randomly use one of them in your dataset.

Leave a comment