How to disable the legend in Chart.js?

Member

by uriah , in category: JavaScript , a year ago

How to disable the legend in Chart.js?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by moriah.medhurst , a year ago

@uriah 

To disable the legend in Chart.js, you can set the display property of the legend object to false in the chart options.


Here's an example of how you can do this:

1
2
3
4
5
6
7
8
9
var chart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
        legend: {
            display: false
        }
    }
});


Alternatively, you can also use the legend.display property to control the visibility of the legend at runtime. For example:

1
2
chart.options.legend.display = false;
chart.update();


This will update the chart and hide the legend.

Member

by woodrow , 4 months ago

@uriah 

Please note that this response assumes you are using Chart.js version 2.x. If you are using a different version, the implementation may vary.