Global setting for tooltips for all chart types
I would like to use the global settings to set the display of the tooltips without having to do this via the "options".
Chart.defaults.global.tooltips.callbacks.label only works for bar, line
Chart.defaults.global.tooltips.callbacks.label = function (
tooltipItem,
data
) {
let dataset = data.datasets[tooltipItem.datasetIndex];
let datasetLabel = dataset.label || ""
let suffix = dataset.unit || ""
console.log('Tooltips.label',tooltipItem, data )
return (
" " + datasetLabel + ": " + dataset.data[tooltipItem.index].toLocaleString() + " " + suffix
);
Am I doing something wrong ?
@zibous which chart types did you try? More specialized types such as the doughnut chart provide an overridden default since the labels change in a different way. See https://github.com/chartjs/Chart.js/blob/2.9/src/controllers/controller.doughnut.js#L98-L117
@etimberg
Thanks for your replay. I try:
pie, polarArea, doughnut -- do not work
bar, line -- ok, works
It may be that I cannot use Chart.defaults.global.tooltips for every chart type ?
What solution is there for this?
You should be able to override the defaults for the other chart types with something like the following. You would need to override it for the 'bubble', 'doughnut', 'pie', 'polarArea', and 'scatter' chart types.
Chart.defaults.doughnut.tooltips.callbacks.label = overrideFunction;
You can also remove the provided default(s):
delete Chart.defaults.pie.tooltips.callbacks.label;
@etimberg
Chart.defaults.doughnut.tooltips.callbacks.label = overrideFunction;
Thanks, now it is working, perfect 馃憤