133
votes

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?

8

8 Answers

298
votes

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/

47
votes

add:

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

in the starting of your script code;

30
votes

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
    }
  }
}
12
votes

It's just as simple as adding this:

legend: {
    display: false,
}

Or if you want you could use this other option which should also work:

Chart.defaults.global.legend.display = false;``
11
votes

You can also put the tooltip onto one line by removing the "title":

this.chart = new Chart(ctx, {
    type: this.props.horizontal ? 'horizontalBar' : 'bar',
    options: {
        legend: {
            display: false,
        },
        tooltips: {
            callbacks: {
                label: tooltipItem => `${tooltipItem.yLabel}: ${tooltipItem.xLabel}`, 
                title: () => null,
            }
        },
    },
});

enter image description here

7
votes
new Chart('idName', {
      type: 'typeChar',
      data: data,
      options: {
        legend: {
          display: false
        }
      }
    });
4
votes

New Solution ChartJS v3.1.1

The above solution is correct for previous versions of chart js prior to v3.1 for v3.1.1 use the following

 ...
 options: {
  plugins:{
   legend: {
    display: false
   }
  }
 }
1
votes

Replace options with this snippet, will fix for Vanilla JavaScript Developers

options: {
            title: {
                text: 'Hello',
                display: true
            },
            scales: {
                xAxes: [{
                    ticks: {
                        display: false
                    }
                }]
            },
            legend: {
                display: false
            }
        }