Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!