0👍
I was able to solve this by using the following formula:
afterLabel : function(tooltipItem, data) {
var allData = data.datasets[tooltipItem.datasetIndex].data;
var tooltipData = allData[tooltipItem.index];
var total = 0;
for (var i=0; i<allData.length; i++) {
total += allData[i];
}
var tooltipPercentage = Math.round((tooltipData / total) * 100);
return tooltipPercentage + '%';
},
It’s not a global formula but it works on each chart I add to the page.
- Chartjs-Displaying line chart for multiple datasets using chart.js
- Chartjs-How to get ChartJs object from dynamically created chart
Source:stackexchange.com