Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda