Chartjs-Chart.js how to show line chart without displaying the labels on xaxis and yaxis

1๐Ÿ‘

โœ…

You can set the ticks display to false like so:

  options: {
    scales: {
      y: {
        ticks: {
          display: false
        }
      },
      x: {
        ticks: {
          display: false
        }
      }
    }
  }

Example:

var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 0],
        borderWidth: 1,
        backgroundColor: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"]
      },
      {
        label: '# of Counts',
        data: [1, 2, 3, 4, 5, 2],
        borderWidth: 1,
        backgroundColor: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"]
      }
    ]
  },
  options: {
    scales: {
      y: {
        ticks: {
          display: false
        }
      },
      x: {
        ticks: {
          display: false
        }
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
const chart = new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.1.0/chart.js" integrity="sha512-LlFvdZpYhQdASf4aZfSpmyHD6+waYVfJRwfJrBgki7/Uh+TXMLFYcKMRim65+o3lFsfk20vrK9sJDute7BUAUw==" crossorigin="anonymous"></script>
</body>

0๐Ÿ‘

if you have a label with ticks you can use

options: {
  scales: {
    y: {
      ticks: {
        display: false
      },
      scaleLabel: {
        display: false,
        labelString: 'Yaxes scaleLabel text'                                
      }
    },
    x: {
      ticks: {
        display: false
      },
      scaleLabel: {
        display: false,
        labelString: 'Xaxes scaleLabel text'                                
      }
    }
  }
}

Leave a comment