Chartjs-ChartJS update data with a colour

0👍

The data does not have a backgroundColor. The backgroundColor is specified in the datasets itself. So you will need to target the specific dataset first you want to push the background color too. Or since you make it a random color you can just put it in your loop where you push the data.

function updateData() {
    removeData(bubbleChart);
    bubbleChart.data.labels.push("Test","test 2",);
    bubbleChart.data.datasets.forEach((dataset) => {
        dataset.data.push([45111.00,61.97,10],[1421413.00,236.55,10],);
        dataset.backgroundColor.push(randomColor())
    });
    bubbleChart.update();
}

Leave a comment