Chartjs-ChartJs(Java) Can I remove only specific gridLines for a Linear Chart withouth removing the labels on xAxis?

0👍

You can set the lineColor of your xAxis gridLines to a function where you set the desired lines that you want to remove to a fully opague collor.

Example:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      borderColor: 'red'
    }]
  },
  options: {
    scales: {
      x: {
        grid: {
          color: (ctx) => (ctx.index % 2 === 0 ? 'rgba(0,0,0,0)' : 'red')
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.1/chart.js"></script>
</body>

Leave a comment