display total count at stacked bar in cahrtjs code example
Example: display total count at stacked bar in cahrtjs
animation: {
onComplete: function() {
var chartInstance = this.chart;
var ctx = chartInstance.ctx;
ctx.textAlign = "left";
ctx.font = "bold 15px Open Sans ";
ctx.textBaseline = 'bottom';
this.data.datasets[0].data.forEach(function(data, index) {
var total = data + this.data.datasets[1].data[index] +this.data.datasets[2].data[index]+this.data.datasets[3].data[index]+this.data.datasets[4].data[index];
var meta = chartInstance.controller.getDatasetMeta(4);
var posX = meta.data[index]._model.x;
var posY = meta.data[index]._model.y;
if(total > 0){
ctx.fillText(total, posX + 6, posY + 8);
ctx.fillStyle = "black";
}
}, this);
}
},