feat: add percentages to tooltip

This commit is contained in:
Anna 2021-10-10 20:26:28 -04:00
parent 11a871fb53
commit b9e6a86a39
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0

View File

@ -1,4 +1,4 @@
(function() {
(function () {
const colours = [
'#D32F2F',
'#1976D2',
@ -17,6 +17,16 @@
const options = {
plugins: {
tooltip: {
callbacks: {
label: function (context) {
let total = context.dataset.data.reduce((total, next) => total + next);
let percentage = (context.raw / total * 100).toFixed(2);
return `${context.label} (${percentage}%)`;
}
}
},
legend: {
display: false,
},