From b9e6a86a393d0e673d616aee4bdfe2c224b6baf0 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sun, 10 Oct 2021 20:26:28 -0400 Subject: [PATCH] feat: add percentages to tooltip --- server/assets/stats.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/assets/stats.js b/server/assets/stats.js index e00b556..81b63d9 100644 --- a/server/assets/stats.js +++ b/server/assets/stats.js @@ -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, },