I'm pretty new in ChartJS and I'm having a horizontal bar chart:
HTML
<canvas id="mybarChart"></canvas>
JavaScript:
var ctx = document.getElementById("mybarChart");
ctx.height = 300;
var mybarChart = new Chart(ctx, {
type: 'horizontalBar',
responsive: true,
data: data,
options: {
legend: {
display: false
},
scales: {
yAxes: [{
display: false,
ticks: {
beginAtZero: true
},
gridLines: {
color: "rgba(0, 0, 0, 0)",
}
}],
xAxes: [{
display: false,
gridLines: {
color: "rgba(0, 0, 0, 0)",
},
barPercentage: 0.5,
categoryPercentage: 0.5
}]
}
}
});
for which I'm trying to add the legend on each bar like
but right now it looks like 
I've tried adding
onAnimationComplete: function () {
var ctx = this.chart.ctx;
ctx.font = this.scale.font;
ctx.fillStyle = this.scale.textColor
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
this.datasets.forEach(function (dataset) {
dataset.points.forEach(function (points) {
ctx.fillText(points.value, points.x, points.y - 10);
});
})
}
but still the same result. What am I doing wrong? I found something here but the labels displayed on each bar are the ticks for Y axes. Is possible to add the legend on each bar and also keep the tooltip?
Thanks in advance!