Chart JS - hide caption

0

Hello

I'm using Chart.js in a project, however I need to hide the caption that appears above the chart.

Does anyone who has worked with this chart know how to hide this part?

Follow the link of the chart I'm using:

link

Here is the code I'm using:

var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["Muito Bom", "Bom", "Regular", "Ruim", "N/A"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2],
            backgroundColor: [
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)'
            ]
        }]
    },
});

I need to hide the label: label: '# of Votes' , but if I leave it blank or if it is removed it will be undefined.

    
asked by anonymous 01.07.2016 / 15:27

3 answers

4

I got the answer, I should insert the following line in the script:

options: {
        legend: {
            display: false
        }
    }

That would look like this:

var ctx = document.getElementById("campos_um");
 var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["Muito Bom", "Bom", "Regular", "Ruim", "N/A"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2],
            backgroundColor: [
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)',
            'rgba(151,187,205,0.5)'
            ]
        }]
    },
    options: {
        legend: {
            display: false
        }
    }
});
    
01.07.2016 / 15:57
4

You can disable using:

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

Source: Documentation

    
01.07.2016 / 15:44
1

Remove caption

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

Remove Tooltip

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

Source: link

    
01.07.2016 / 17:32