I am using angular-chart.js to draw some charts. We know now chart.js supports stacked bar chart. But I have not found how to show numbers in each bar, like following: From above pic we can see each bar has number on it. Does anyone know how to realize that in angular-chart.js?
angular-chart.js : how to show numbers in each bar of stacked bar chart
5.7k views Asked by ahwyX100 At
2
There are 2 answers
0
On
You can show numbers in each bar of stacked bar chart by adding this code in your options function
animation: {
duration: 1,
onComplete: function () {
var chartInstance = this.chart,
ctx = chartInstance.ctx;
ctx.textAlign = 'center';
ctx.fillStyle = "rgba(0, 0, 0, 1)";
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function (dataset, i) {
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function (bar, index) {
var data = dataset.data[index];
ctx.fillText(data, bar._model.x, bar._model.y - 5);
});
});
}
}
You can do this, it will be displayed as a tooltip,
DEMO