Accepted answer

you can try one thing

try to separate the legend into an different div. now you have full control of the div you can use custom placement and css of your own consider the following code :

 <div id="js-legend" class="chart-legend"></div>
 document.getelementbyid('js-legend').innerhtml = mychart.generatelegend();

for reference see this fiddle

for handling legend interactive you need to extend the callback function and manipulate like this :

$("#js-legend > ul > li").on("click",function(e){
        var index = $(this).index();
        var ci = e.view.mychart;
        var curr =[0]._meta[0].data[index];
        curr.hidden = !curr.hidden

for legend in action see this fiddle

explanation :

i binded chart to window so that event view can get it, and later by the index manipulated the data and updated runtime used few css tricks to illustrate the strike effect.


as mentioned in other answers, a possible solution is externalize the legend as plain html div, on which you have full control.

now, in chartjs v3 the chart.generatelegend() function has been removed.

the maintainers, though, have published the so called htmllegend plugin which externalises the legend, here is the link:

html legend (external div) - chartjs docs

the plugin creates an interactive legend whose items can be clicked to show/hide datasets as in the original one.

note: although having a scrollable legend might come in handy, having so many items in a legend could make the chart illegible and should make one consider representing data in a different way, perhaps by splitting data in more charts or introducing search functions


i did not found any solution for this, but you can turn off legend if too many labels are to be shown (i did it in my project) - here is set to max 15 labels:

options : {
        responsive: true,
        maintainaspectratio: false,
        layout: {
          padding: {
             left     : 0,
             right    : 0,
             top      : 0,
             bottom   : 0
        animation: {
          duration : 5000
        legend: {
          display: this.chartvalues.length <= 15,

you can also make place for rendering charts bigger. add this to your scss file:

    height: 300px !important;

i hope it gonna help someone

Related Query

More Query from same tag