How to remove grid on chart.js?

by scotty_walker , in category: Javascript , a year ago

How to remove grid on chart.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , a year ago

@scotty_walker 

To remove the grid on a Chart.js chart, you can use the ticks configuration options for the X and Y axes and set display to false for the gridLines property.


Here's an example of how to remove the grid:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255,99,132,1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      y: {
        ticks: {
          display: false // Remove Y-axis ticks
        },
        gridLines: {
          display: false // Remove Y-axis grid lines
        }
      },
      x: {
        ticks: {
          display: false // Remove X-axis ticks
        },
        gridLines: {
          display: false //Remove X-axis grid lines
        }
      }
    }
  }
});


In this example, both the X and Y axes' ticks and grid lines are removed.

Related Threads:

How to remove the line/rule of an axis in chart.js?
How to remove the white space around a chart in chart.js?
How to remove background color and color example from tooltip in chart.js?
How to use grid in tailwind css?
How to keep individual grid column height in tailwind?
How to hide overflow in grid column with tailwind css?