Categories
JavaScript Answers

How to remove x-axis label and text in Chart.js and JavaScript?

Spread the love

Sometimes, we want to remove x-axis label and text in Chart.js and JavaScript.

In this article, we’ll look at how to remove x-axis label and text in Chart.js and JavaScript.

How to remove x-axis label and text in Chart.js and JavaScript?

To remove x-axis label and text in Chart.js and JavaScript, we can set some properties in options.

In Chart.js 3.x, we write

const chart = new Chart(ctx, {
  //...
  options: {
    scales: {
      x: {
        display: false,
      },
    },
  },
});

to remove x-axis labels and grid chart lines.

We write

const chart = new Chart(ctx, {
  //...
  options: {
    scales: {
      x: {
        ticks: {
          display: false,
        },
      },
    },
  },
});

to remove only x-axis labels.

In Chart.js 2.x, we write

const chart = new Chart(ctx, {
  //...
  options: {
    scales: {
      xAxes: [
        {
          display: false,
        },
      ],
    },
  },
});

to remove x-axis labels and grid chart lines.

We write

const chart = new Chart(ctx, {
  //...
  options: {
    scales: {
      xAxes: [
        {
          ticks: {
            display: false,
          },
        },
      ],
    },
  },
});

to remove only x-axis labels.

Conclusion

To remove x-axis label and text in Chart.js and JavaScript, we can set some properties in options.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *