How to remove the line/rule of an axis in Chart.js?
Asked Answered
S

10

12

I managed to remove all horizontale lines/rules in my chart using this:

scales: {
       xAxes: [{
        gridLines: {
            display: false
        }  
    }]
}

But I also want to get rid of the rule/bar that represents the Y-axis as well. But I want to keep the labels:

enter image description here

Unfortunately I can't find any option for that. I can only remove the whole axis including labels.

I'm using Chart.js 2.3.

Shoa answered 10/11, 2016 at 8:23 Comment(2)
in x axis gridLines u make it as false and looking in the y axis to display the falseHellbender
@Hellbender The example show ho to remove the horizontal gridlines. But this option doesn't remove the actual line for the axis (horizontally or vertically doesn't matter). So I'm looking for an option how to remove the actual line of the axis not only the grid lines.Shoa
S
32

I found a way to remove this line. It's actually called the border of the axis and there's an option for it, see "Grid Line Configuration":

scales: {
    yAxes: [{
        gridLines: {
            drawBorder: false,
        }
    }]
}
Shoa answered 10/11, 2016 at 9:27 Comment(3)
This doesnot work. DownVoted because of that (sorry) this code worked for me: gridLines: { display:false } Update it and I will upvote again!Flita
worked for me, I already had display:none but was not sufficient for that borders. thanksWilton
Doesn't work in v.2.9.0, but fixed in v.3.0.0 github.com/chartjs/Chart.js/issues/6876Cicala
M
6

In v3 you can do:

options: {
  scales: {
    y: {
      grid: {
        drawBorder: false,
      }
    }
  }
}

https://www.chartjs.org/docs/master/axes/styling#grid-line-configuration

Milwaukee answered 30/3, 2021 at 8:37 Comment(0)
U
4

This should work

 options: {
     scales: {
          yAxes: [{
               gridLines: {
                  display: false,
              }
          }]
     },
  }
Uniseptate answered 8/4, 2019 at 13:29 Comment(0)
H
4

This worked for me in version 2.8.0 -

scales: {
    yAxes: [{
        gridLines: {
            tickMarkLength: false,
        }
    }]
}
Haemolysin answered 16/6, 2020 at 4:1 Comment(0)
F
3

The left line is still coming from the x axis grid lines. Changing the 'zeroLineColor' of the x axis to 'transparent' hid it.

xAxes:[{
gridLines:{
zeroLineColor:'transparent'
}}]

Source: https://github.com/chartjs/Chart.js/issues/3950

Frown answered 10/2, 2021 at 22:28 Comment(0)
C
3

In the version 4.x.x you do it like this:

options: {
  scales: {
    y: {
       border: {
        display: false,
      },
    },
    x: {
      grid: {
        drawOnChartArea: false,
      },
    },
  },
},

The border in y is the option that specifically does what you are asking. I added the x for users that also want to see how to hide the rest of the x axis lines.

Cottonseed answered 9/4, 2023 at 15:40 Comment(0)
I
0
gridLines: {zeroLineColor: 'transparent'}
Idiographic answered 7/5, 2020 at 9:55 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBlackstone
While this code may solve the OP's issue, it is better to add context, or an explanation as to why this solves the OP's problem, so future visitors can learn from your post, and apply this knowledge to their own issues. High Quality Answers are much more likely to be upvoted, and contribute to the value and quality of SO as a platform. You can also add a link to documentation, if that helps.Dolphin
@john An answer that's not fully explained, incomplete, or just plain wrong is still an answer. If you think it's a bad answer, that's what downvotes are for. See when to flag an answer as “not an answer”?Lacerta
C
0

this workerd for me yAxes: [ { gridLines: { display: false, }, }, ],

Ceresin answered 10/4, 2021 at 7:52 Comment(0)
G
0

This worked for me in v4.4


scales: {
x: {
  border: {
    display: false,
  },
},
y: {
  border: {
    display: false,
  },
}

Generic answered 22/10, 2023 at 2:59 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Marlonmarlow
H
-2

You can use the scaleLineColor: 'transparent' it will remove the y any x axis

Hellbender answered 10/11, 2016 at 8:30 Comment(6)
This will remove the labels as well, right? The labels should stay. Only the line should be gone.Shoa
you want to remove both the axis lines?Hellbender
Actually only the Y-axis line. Is this a global setting? I can't find it in the Chart.js docs.Shoa
new Chart(ctx, { type: 'line', data: data, options: { scales: { yAxes: [{ display: false }] } } }); please have a look on the link it will help you chartjs.org/docs/#line-chart-chart-optionsHellbender
Thanks a lot for your help - I found an option to remove the line, which is actually the "´border`" option of the gridlines.Shoa
ha ha ha okie thank you.. give the support flag to my comment :PHellbender

© 2022 - 2024 — McMap. All rights reserved.