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

145
Vistas
Change color on labels in chart.js

How do I change the color on the labels to blue? Is it possible to switch between colors, lets say blue, and red by clicking on a button?`

The reason why I ask for the switch, is because I might create a light/dark mode, and then it could be nice to change colors in the chart depending on this. But if its not possible then blue would be the best.

    const data = {
        labels: [
            'New',
            'To Do',
            'In Progress',
            'Resolved'
        ],
        datasets: [{
            label: 'WDC',
            data: [300, 50, 100, 20],
            backgroundColor: [
                'rgb(126, 191, 241)',
                'rgb(255, 159, 64)',
                'rgb(255, 255, 0)',
                'rgb(160, 160, 160)'
            ],
            borderColor: [
                'rgb(126, 191, 241)',
                'rgb(255, 159, 64)',
                'rgb(255, 255, 0)',
                'rgb(160, 160, 160)'
            ],
            backgroundColor: [
                'rgb(126, 191, 241)',
                'rgb(255, 159, 64)',
                'rgb(255, 255, 0)',
                'rgb(160, 160, 160)'
            ],
            hoverOffset: 4
        }]
    };
    const config = {
        type: 'pie',
        data: data,
        options: {
            responsive: true,
            maintainAspectRatio: false,
            layout: {
                padding: 20
            },
            plugins: {
                legend: {
                    position: 'top'
                }
            }
        }
    };
    const myChart = new Chart(
        document.getElementById('myChart'),
        config
    );
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div id="wdc_canvas" style="position: relative; height:30vh; width:40vw">
    <canvas id="myChart" width="785" height="389" style="z-index: 8; display: block; box-sizing: border-box; height: 389px; width: 785px;"></canvas>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure if you meant the labels in the legend or in the tooltip but here are the options for both of them:

const data = {
  labels: [
    'New',
    'To Do',
    'In Progress',
    'Resolved'
  ],
  datasets: [{
    label: 'WDC',
    data: [300, 50, 100, 20],
    backgroundColor: [
      'rgb(126, 191, 241)',
      'rgb(255, 159, 64)',
      'rgb(255, 255, 0)',
      'rgb(160, 160, 160)'
    ],
    borderColor: [
      'rgb(126, 191, 241)',
      'rgb(255, 159, 64)',
      'rgb(255, 255, 0)',
      'rgb(160, 160, 160)'
    ],
    backgroundColor: [
      'rgb(126, 191, 241)',
      'rgb(255, 159, 64)',
      'rgb(255, 255, 0)',
      'rgb(160, 160, 160)'
    ],
    hoverOffset: 4
  }]
};
const config = {
  type: 'pie',
  data: data,
  options: {
    responsive: true,
    maintainAspectRatio: false,
    layout: {
      padding: 20
    },
    plugins: {
      tooltip: {
        bodyColor: 'blue'
      },
      legend: {
        labels: {
          color: 'blue',
        },
        position: 'top'
      }
    }
  }
};
const myChart = new Chart(
  document.getElementById('myChart'),
  config
);
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div id="wdc_canvas">
  <canvas id="myChart"></canvas>
</div>

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