Chart.js v2 hide dataset labels

I have the following codes to create a graph using Chart.js v2.1.3:

var ctx = $('#gold_chart');
var goldChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: dates,
        datasets: [{
            label: 'I want to remove this Label',
            data: prices,
            pointRadius: 0,
            borderWidth: 1
        }]
    }
});

The codes look simple, but I cannot remove the label from the graph. I tried a lot of solutions I found online, but most of them use Chart.js v1.x.

How can I remove the dataset labels?


Solution 1:

Just set the label and tooltip options like so

...
options: {
    legend: {
        display: false
    },
    tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
}

Fiddle - http://jsfiddle.net/g19220r6/

Solution 2:

As of 2021, the namespace has changed from options.legend to options.plugins.legend. This simple code worked for me -

data{
...
},
options: {
  plugins: {
    legend: {
      display: false
    }
  }
}

Solution 3:

add:

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

in the starting of your script code;