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

157
Vistas
Data Labels wrongly positioned on bar chart - chartjs

I'm using chartjs-plugin-datalabels to show values on chart, but the labels are not centered. The main part is in the datasets.datalabels where I can override default settings, which sets to center anyway, but wanted to show where its done. I have tried positione it to the right, but as the value getting bigger, the datalabel is less centered.

bar chart

Chart.register(ChartDataLabels);

const data_tafkidim_cat_count = {
  labels: window.TafkidimCatCount.map((el) => el.TafkidCat.split(' ')).slice(0, pagination['tafkidim_cat_count'].show),
  datasets: [
    {
      data: window.TafkidimCatCount.map((el) => el.Total),
      backgroundColor: Setcolors(),
      borderColor: Setcolors(1),
      borderWidth: 1,
      datalabels: {
        anchor: 'center',
        align: 'center',
      },
    },
  ],
};
const config_tafkidim_cat_count = {
  type: 'bar',
  data: data_tafkidim_cat_count,
  options: {
    scales: {
      x: {
        grid: {
          borderColor: '#829AB1',
        },
        ticks: {
          color: '#627D98',
        },
        reverse: true,
      },
      y: {
        grid: {
          borderColor: '#829AB1',
        },
        beginAtZero: true,
        ticks: {
          color: '#627D98',
        },
      },
    },
    plugins: {
      title: {
        text: TL['tafkidim_cat_count'],
        padding: {
          bottom: 20,
        },
      },
      legend: {
        display: false,
      },
      tooltip: {
        callbacks: {
          title: (context) => {
            return context[0].label.replaceAll(',', ' ');
          },
        },
      },
    },
  },
};
const tafkidim_cat_count = new Chart('#tafkidim-cat-count'.Element().getContext('2d'), config_tafkidim_cat_count);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

solved it with

textAlign = "center"

apparently the default is "start".

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