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

113
Vistas
zeroLineColor and zeroLineWidth not working for the x-axis in Chartjs

How to change the width and the color of the x-axis (horizontal axis) in Chartjs? It seems to work using zeroLineColor and zeroLineWidth for the y-axis (vertical one), but it does not work for the x-axis.

If we add:

ticks: {
  beginAtZero: true
}

It works as expected, but I don't want the vertical ticks to start from 0.

Is there a way to make this happen?

scales: {
        xAxes: [{
          gridLines: {
            zeroLineColor: 'black', // WORKS
            zeroLineWidth: 2 // WORKS
          },
          display: true
        }],
        yAxes: [{
          gridLines: {
            zeroLineColor: 'black', // DOES NOT WORK
            zeroLineWidth: 2, // DOES NOT WORK
          },
          id: 'y-axis-0',
          display: true,
          ticks: {
            // beginAtZero: true // This is what I dont't want to use
          }
        }]
      }

This is the result I get with the previous code: Graphic

As you can see, the x-axis is displayed without changes in color or width.

I'm using version 2.9.4 of the Chartjs library.

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

0

Go to the .js of the library (in my case: 'node_modules/chart.js/dist/Chart.bundle.js') and, in the line 12202, you will find this conditional:

if (i === me.zeroLineIndex && options.offset === offsetGridLines) {

Transform it into this:

if ((i === me.zeroLineIndex || (!isHorizontal && i === ticksLength - 1)) && options.offset === offsetGridLines) {

Then, do whatever compression or manipulation of the file you need to do to add it to your project.

It's not the best solution, but it's the one I came up with.

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