10👍
✅
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
}
}
24👍
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
}
}
}
});
1👍
Update for V4:
If you want to remove x completely with labels, just add this to options:
options: {
scales: {
x: {
display: false
}
}
}
0👍
You can use filter to remove out the label you don’t want to show
options: {
plugins: {
legend: {
labels: {
filter: (l) => (l.text !== 'Label you want to remove')
}
}
}
}
Source:stackexchange.com