Is there total value for context.dataset ? #11205
-
Hi! I'm calculating total value on the fly to get percentage in the label. Like this Chart.defaults.plugins.tooltip.callbacks.label = function (context) {
const total = context.dataset.data.reduce((x, y) => x + y, 0);
const currentValue = context.parsed;
const percentage = ((currentValue / total) * 100).toFixed(2);
return `${currentValue} (${percentage}%)`;
};
Chart.defaults.plugins.tooltip.callbacks.title = function (context) {
return context.label;
}; But maybe there is already total value of dataset? |
Beta Was this translation helpful? Give feedback.
Answered by
LeeLenaleee
Mar 29, 2023
Replies: 2 comments
-
no there is no sum by default |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AucT
-
Consider to add it |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no there is no sum by default