10

我设法使用以下方法删除了图表中的所有水平线/规则:

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

但我也想摆脱代表 Y 轴的规则/条。但我想保留标签

在此处输入图像描述

不幸的是,我找不到任何选择。我只能删除包括标签在内的整个轴。

我正在使用 Chart.js 2.3。

4

8 回答 8

29

我找到了删除这条线的方法。它实际上被称为border轴的,并且有一个选项,请参阅“网格线配置”

scales: {
    yAxes: [{
        gridLines: {
            drawBorder: false,
        }
    }]
}
于 2016-11-10T09:27:07.987 回答
4

这应该工作

 options: {
     scales: {
          yAxes: [{
               gridLines: {
                  display: false,
              }
          }]
     },
  }
于 2019-04-08T13:29:13.333 回答
4

这在 2.8.0 版中对我有用-

scales: {
    yAxes: [{
        gridLines: {
            tickMarkLength: false,
        }
    }]
}
于 2020-06-16T04:01:53.020 回答
2

左边的线仍然来自 x 轴网格线。将 x 轴的 'zeroLineColor' 更改为 'transparent' 隐藏它。

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

来源:https ://github.com/chartjs/Chart.js/issues/3950

于 2021-02-10T22:28:28.793 回答
1

v3中,您可以执行以下操作:

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

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

于 2021-03-30T08:37:51.947 回答
0
gridLines: {zeroLineColor: 'transparent'}
于 2020-05-07T09:55:49.607 回答
0

这个为我工作 yAxes: [ { gridLines: { display: false, }, }, ],

于 2021-04-10T07:52:25.790 回答
-2

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

于 2016-11-10T08:30:06.037 回答