score:8

Accepted answer

The label should be inside datasets such as

type: 'horizontalBar',
data: {  
  labels: [data1, data2],
  datasets: [{
    label: 'put it here', // => here
    backgroundColor: ['rgb(240,61,74)', 'rgb(0, 156, 255)'],
    data: [data1.count, data2.count],
  }]
},

so you won't get undefined

Updated: if you don't want to see it, put legend configuration inside the options. Apparently, I saw that your legend is outside options object.

options: {        
  legend: {
    display: false
  }
}

score:14

Note, the accepted answer is outdated for 3.x. To remove the legend you now have to specify the plugin. https://www.chartjs.org/docs/latest/configuration/legend.html

eg

var chart = new Chart(ctx, {
   type: 'bar',
   data: data,
   options: {
      plugins: {
         legend: {
            display: false
         }
      }
    }
});

Related Query

More Query from same tag