Chart.js v2 - hiding grid lines

后端 未结 7 1982
旧时难觅i
旧时难觅i 2020-12-12 15:25

I am using Chart.js v2 to draw a simple line chart. Everything looks fine, except there are grid lines that I don\'t want:

The documentation for Line Chart

相关标签:
7条回答
  • 2020-12-12 15:46

    I found a solution that works for hiding the grid lines in a Line chart.

    Set the gridLines color to be the same as the div's background color.

    var options = {
        scales: {
            xAxes: [{
                gridLines: {
                    color: "rgba(0, 0, 0, 0)",
                }
            }],
            yAxes: [{
                gridLines: {
                    color: "rgba(0, 0, 0, 0)",
                }   
            }]
        }
    }
    

    or use

    var options = {
        scales: {
            xAxes: [{
                gridLines: {
                    display:false
                }
            }],
            yAxes: [{
                gridLines: {
                    display:false
                }   
            }]
        }
    }
    
    0 讨论(0)
  • 2020-12-12 15:51
    options: {
        scales: {
            xAxes: [{
                gridLines: {
                    drawOnChartArea: false
                }
            }],
            yAxes: [{
                gridLines: {
                    drawOnChartArea: false
                }
            }]
        }
    }
    
    0 讨论(0)
  • 2020-12-12 15:59

    If you want them gone by default, you can set:

    Chart.defaults.scale.gridLines.display = false;
    
    0 讨论(0)
  • 2020-12-12 15:59

    The code below removes remove grid lines from chart area only not the ones in x&y axis labels

    Chart.defaults.scale.gridLines.drawOnChartArea = false;
    
    0 讨论(0)
  • 2020-12-12 16:04

    Please refer to the official documentation:

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

    Below code changes would hide the gridLines:

            gridLines: {
                display:false
            }
    

    0 讨论(0)
  • 2020-12-12 16:07

    If you want to hide gridlines but want to show yAxes, you can set:

    yAxes: [{...
             gridLines: {
                            drawBorder: true,
                            display: false
                        }
           }]
    
    0 讨论(0)
提交回复
热议问题