You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The tooltip on a pie chart consists of label and the number (XYZ: 100). It would be nice if there was an easy way to change it. I'm thinking of something along the following lines:
which should result in a tooltip of A: 6 minutes. This example is also my usecase. The numbers I'm displaying in the pie chart are time durations.
To make it more general you could add a formatTooltip function instead of dataLabels and optionally allow arbitrary DOM and not just text (unless you are drawing the tooltip on the canvas of course).
Feature Use Case
see example above
Possible Implementation
defaults._set('doughnut', {
// HERE I LEFT OUT A LOT OF CODE
tooltips: {
callbacks: {
title: function() {
return '';
},
label: function(tooltipItem, data) {
var dataLabel = data.labels[tooltipItem.index];
// CHANGE STARTS HERE
var dataSet = data.datasets[tooltipItem.datasetIndex];
var value;
if(dataSet.dataLabels)
{
value = ': ' + dataSet.dataLabels[tooltipItem.index];
}else{
value = ': ' + dataSet.data[tooltipItem.index];
}
// ENDS HERE
if (helpers.isArray(dataLabel)) {
// show value on first line of multiline label
// need to clone because we are changing the value
dataLabel = dataLabel.slice();
dataLabel[0] += value;
} else {
dataLabel += value;
}
return dataLabel;
}
}
}
The text was updated successfully, but these errors were encountered:
@k44me I'm not sure if we'd want to add that into the default tooltip callback since you could easily change the default for your use case.
In terms of the tooltip content, we draw the tooltip on the canvas so we are limited in the API that we expose. We do have some samples though that show how to create an HTML tooltip.
Closing per my comment from 2019. I don't think we want to ship this in the core. A good solution might be to have a separate lib that provides a more advanced tooltip config function. This would make a good opt-in piece of functionality for users who need it
Feature Proposal
The tooltip on a pie chart consists of label and the number (
XYZ: 100
). It would be nice if there was an easy way to change it. I'm thinking of something along the following lines:which should result in a tooltip of
A: 6 minutes
. This example is also my usecase. The numbers I'm displaying in the pie chart are time durations.To make it more general you could add a
formatTooltip
function instead ofdataLabels
and optionally allow arbitrary DOM and not just text (unless you are drawing the tooltip on the canvas of course).Feature Use Case
see example above
Possible Implementation
The text was updated successfully, but these errors were encountered: