Chartjs-Show percentage of category relative to stacked bar in Chart.js

2👍

You can use dataLabels plugin. I made an example for you on this link.

    plugins: {
        datalabels: {
            formatter: function(value, context) {
            if(context.chart.data.datasets[context.datasetIndex] != null){
                    var barTotal = context.chart.data.datasets.map(function(x){return x.data[context.dataIndex]}).reduce((a, b) => a + b, 0);
                    return (value * 100 /  barTotal).toFixed(2);
                }
            }
        }
    }

If you want to see the percentage on hover, you can check tooltip functions and aplly the same function for it.

Leave a comment