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

163
Vistas
Why my ChartJs only Coloring one section?

I have created a Bar Chart. It shows data grouped by Year. I have set the color to each datatype, but the ChartJS only shows it on 1 Year

ChartJS only Coloring 1 Year

Here's the code:

const data = {
      labels: Syear,
            datasets: [{
                label: 'Jumlah Korban Meninggal 5 Tahun terakhir',
                data: Sdead_total,
                backgroundColor: ['rgba(255, 99, 132, 0.2)'],
                borderColor: ['rgba(255, 99, 132, 1)'],
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Hilang 5 Tahun terakhir',
                data: Smissing_total,
                backgroundColor: ['rgba(54, 162, 235, 0.2)'],
                borderColor: ['rgba(54, 162, 235, 1)'],
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Luka Berat 5 Tahun terakhir',
                data: Sserious_woundTotal,
                backgroundColor: ['rgba(255, 206, 86, 0.2)'],
                borderColor: ['rgba(255, 206, 86, 1)'],
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Luka Ringan 5 Tahun terakhir',
                data: Sminor_injuriesTotal,
                backgroundColor: ['rgba(75, 192, 192, 0.2)'],
                borderColor: ['rgba(75, 192, 192, 1)'],
                borderWidth: 1
            }
          ]
    };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is happening because you are using V2 of the lib and providing the backgroundColor as an array which means take the index of the color in the array and assign it to that bar, if there is no color don't use any.

So chaning your code to this will resolve the issue:

const data = {
      labels: Syear,
            datasets: [{
                label: 'Jumlah Korban Meninggal 5 Tahun terakhir',
                data: Sdead_total,
                backgroundColor: 'rgba(255, 99, 132, 0.2)',
                borderColor: 'rgba(255, 99, 132, 1)',
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Hilang 5 Tahun terakhir',
                data: Smissing_total,
                backgroundColor: 'rgba(54, 162, 235, 0.2)',
                borderColor: 'rgba(54, 162, 235, 1)',
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Luka Berat 5 Tahun terakhir',
                data: Sserious_woundTotal,
                backgroundColor: 'rgba(255, 206, 86, 0.2)',
                borderColor: 'rgba(255, 206, 86, 1)',
                borderWidth: 1
            },
            {
                label: 'Jumlah Korban Luka Ringan 5 Tahun terakhir',
                data: Sminor_injuriesTotal,
                backgroundColor: 'rgba(75, 192, 192, 0.2)',
                borderColor: 'rgba(75, 192, 192, 1)',
                borderWidth: 1
            }
          ]
    };
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