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

800
Vistas
How to change font size and color + move datalabels in chart.js with chartjs-plugin-datalabels?

I want to add datalabels to the top of each bar and color them in black and make it in bigger font. Like this: my chart with necessary labels

But all that I tried don't change the chart.

I add chartjs and charts-plugin-datalabels:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.8.0/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.0.0/chartjs-plugin-datalabels.js"></script>

Chart creating function:

function bars_chart(data, period) {
        Chart.register(ChartDataLabels)
        document.querySelector('#chartContainer').innerHTML = '<canvas id="bar-chart-horizontal"></canvas>'

        var chartConfig = {
          type: 'bar',
          data: {
              labels: period,
              datasets: data
            },
          options: {
              responsive: true,
              plugins: {
                  dataLabels: {
                      font: {
                          color: "#000000",
                          size: 25
                      },
                      color: "#000000"
                  },
                  legend: {
                      position: 'top',
                  },
                  title: {
                      display: true,
                      text: 'Chart.js Bar Chart'
                  },
              }
          },
        };

        new Chart(document.getElementById("bar-chart-horizontal"), chartConfig);
    }

It looks like there is a simple solution but I can't find it)

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

0

Your namespace is wrong, you putted a capital L in there while it needs to be fully lower case. After that you can set anchor and align to 'end' to get the value on top of the bars:

Chart.register(ChartDataLabels)

const options = {
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: 'pink'
    }]
  },
  options: {
    plugins: {
      datalabels: {
        color: 'black',
        font: {
          size: 40
        },
        anchor: 'end',
        align: 'end'
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.8.0/chart.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.0.0/chartjs-plugin-datalabels.js"></script>
</body>

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