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

342
Vistas
ChartJS Horizontal bars barely visible with 50 records on the Y axis

Is there a way to set the vertical thickness of the horizontal bars in ChartJS(3.7.0). Or change the zoom level or something?

I have a recordset with 50 rows which should show 50 horizontal bars. However when the chart is rendered. The lines representing the horizontal bars are barely visible.

I am using this config:

        const config = {
          type: 'bar',
          data: chart_data,
          options: {
            maintainAspectRatio: false,
            scales: {
                yAxes: [{
                    barThickness: 20,  // number (pixels) or 'flex'
                    maxBarThickness: 22 // number (pixels)
                }]
            },
            indexAxis: 'y',
            plugins: {
              legend: {
                position: 'right',
              },
            }
          }
        };

I am also setting the bar and max thickness in each dataset as well. Also set the height of the parent <div> which houses the <canvas> tag to a large value 3200px.

Thanks

barely visible horizontal bars

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

0

Without seeing more of your code, it's almost impossible to find out, why the thickness of the bars in your chart is not what you expect.

The following points however are worth knowing when working with Chart.js v3:

  • scales.[x/y]Axes.barThickness was moved to dataset option barThickness
  • scales.[x/y]Axes.maxBarThickness was moved to dataset option maxBarThickness

More details can be found in the 3.x Migration Guide or in the Chart.js v3 documentation here.

Please take a look at below runnable script and see how it could be done in your case.

const data = [...Array(50)].map(e => ~~(Math.random() * 20 + 1));
const colors = ['255, 99, 132', '54, 162, 235', '255, 206, 86', '231, 233, 237', '75, 192, 192',   '151, 187, 205', '220, 220, 220', '247, 70, 74', '70, 191, 189', '253, 180, 92', '148, 159, 177', '77, 83, 96'];

new Chart('chart', {
  type: 'bar',
  plugins: [{
    beforeLayout: chart => chart.options.scales.y1.labels = chart.data.datasets.filter((ds, i) => !chart.getDatasetMeta(i).hidden).map(ds => ds.label)
  }],
  data: {
    datasets: data.map((v, i) => ({
      label: i + 1,
      data: [{ x: v, y: i }],
      backgroundColor: 'rgba(' + colors[i % colors.length] + ', 0.4)',
      borderColor: 'rgb(' + colors[i % colors.length] + ')',
      borderWidth: 1,
      categoryPercentage: 1
    }))
  },
  options: {
    indexAxis: 'y',    
    plugins: {
      legend: {
        position: 'right',
      },
      tooltip: {
        callbacks: {
          title: () => undefined
        }
      }
    },
    scales: {
      y: {
      },
      y1: {
        offset: true,
        gridLines: {
          display: false
        }
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js"></script>
<canvas id="chart" height="600"></canvas>

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