Categories
JavaScript Answers

How to remove legend on charts with Chart.js v2 and JavaScript?

Spread the love

Sometimes, we want to remove legend on charts with Chart.js v2 and JavaScript.

In this article, we’ll look at how to remove legend on charts with Chart.js v2 and JavaScript.

How to remove legend on charts with Chart.js v2 and JavaScript?

To remove legend on charts with Chart.js v2 and JavaScript, we can set the options.legend to false.

For instance, we write

const chart1 = new Chart(canvas, {
  type: "pie",
  data: data,
  options: {
    legend: {
      display: false,
    },
    tooltips: {
      enabled: false,
    },
  },
});

to create the Chart object with the options.legend property set to false to disable the legend.

Conclusion

To remove legend on charts with Chart.js v2 and JavaScript, we can set the options.legend to false.

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 *