Search code examples
javascriptjquerychart.jschartjs-2.6.0

How to remove the coloured rectangle(dataset label) in chartJS


I have used the chartjs 2.8 and drew a Bar chart using the same. There is one rectangle coming above the chart with filled color (https://i.sstatic.net/Kh0pl.jpg). I have tried multiple ways to remove that but fails.

I have tried the below code but no luck.

legend: {
    display: false,
}

Here is my current code

var ctx = document.getElementById("myChart").getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: chartData1,
        options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});

Could you anyone please tell me how to remove that?


Solution

  • It should be this, if it doesnt work you aren't on version 2 or something else is wrong.

    var ctx = document.getElementById("myChart").getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: chartData1,
        options: {
            legend: {
                display: false,
            },
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true
                    }
                }]
            }
        }
    });