Chart.js 3.4/Vue3 How to hide border ticks and set specific amount of grid lines

๐Ÿ‘:1

You can make use of the drawTicks and count propertys to achieve what your want.

Live example:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3]
    }]
  },
  options: {
    scales: {
      y: {
        ticks: {
          count: 5,
          padding: 10
        },
        grid: {
          drawTicks: false
        }
      },
      x: {
        ticks: {
          padding: 10
        },
        grid: {
          drawTicks: false
        }
      }
    }
  }
}

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.0/chart.js"></script>
</body>

Leave a comment