Chart.js: Conditionally display gridlines? [QUESTION]

Created on 3 Feb 2017  路  5Comments  路  Source: chartjs/Chart.js

Is there a way to conditionally hide gridlines based on the dataset?
chart-lines

support

Most helpful comment

You can remove individual lines. I also made a mistake in my previous comment. You return undefined not NaN.

options: : {
  scales: {
    yAxes: [{
      ticks: {
        callback: function(tick, index, ticksArray) {
          // return the string representation of the tick value. Return undefined to hide the grid line
        }
      }
    }]
  }
}

All 5 comments

@javalen in the scaleOptions.ticks.callback property, you can return NaN to hide the grid line.

Thanks for the information, will that remove a single horizontal line or all horizontal lines on the chart?. I'm trying to selectively remove or hide some lines while showing others at the same time. Thanks again

You can remove individual lines. I also made a mistake in my previous comment. You return undefined not NaN.

options: : {
  scales: {
    yAxes: [{
      ticks: {
        callback: function(tick, index, ticksArray) {
          // return the string representation of the tick value. Return undefined to hide the grid line
        }
      }
    }]
  }
}

Works perfectly, Thanks!

Awesome 馃槃

Was this page helpful?
0 / 5 - 0 ratings