Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
ChartJS update data with a colour

Evening all, I have a function to update the data in my ChartJS chart, however it will always update with a solid blue colour, I also have a function to get a random rgba colour however I am having trouble mating the two, code below and any help would be appreciated!

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],);
    });
    bubbleChart.data.backgroundColor.push(randomColor())
    bubbleChart.update();
}

I get the following error:

TypeError: undefined is not an object (evaluating 'bubbleChart.backgroundColor.push')

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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();
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!