Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing legend on charts with chart.js v2

People also ask

How do I remove a legend from a chart?

Tip: To quickly remove a legend or a legend entry from a chart, you can select it, and then press DELETE. You can also right-click the legend or a legend entry, and then click Delete.

How do you hide labels in Chartjs?

You can hide datasets labels in Chart. js by applying 'display: false' into legend option.

How do you show legend in Chartjs?

js (3.6. 0), you can control the Legend display with the following code: const options = { plugins: { ... legend: { position: "right", // by default it's top }, ... }, };

What is a legend in chart JS?

The chart legend displays data about the datasets that are appearing on the chart.


The options object can be added to the chart when the new Chart object is created.

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

You can change default options by using Chart.defaults.global in your javascript file. So you want to change legend and tooltip options.

Remove legend

Chart.defaults.global.legend.display = false;

Remove Tooltip

Chart.defaults.global.tooltips.enabled = false;

Here is a working fiddler.


From chart.js version 3.x onwards: legend, title and tooltip namespaces are moved from options to options.plugins.

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

Modifying Ishan's answer

If you are using react like me,

const data = {
...
}

const options = {
  plugins: {
    legend: {
      display: false,
    },
  },
};


<Bar data={data} options={options} />