Skip to content

Commit d4a8075

Browse files
committed
feat: improve default tooltip
1 parent 63c9eff commit d4a8075

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/generateChartComponent.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ export default function generateChartComponent (name, type) {
4949
return {
5050
tooltips: {
5151
enabled: false,
52-
custom: customTooltips
52+
custom: customTooltips,
53+
intersect: true,
54+
mode: 'index',
55+
position: 'nearest',
56+
callbacks: {
57+
labelColor (tooltipItem, chart) {
58+
function getValue (prop) {
59+
return typeof prop === 'object' ? prop[tooltipItem.index] : prop
60+
}
61+
const dataset = chart.data.datasets[tooltipItem.datasetIndex]
62+
//tooltipLabelColor is coreUI custom prop used only here
63+
const backgroundColor = getValue(
64+
dataset.tooltipLabelColor ||
65+
dataset.pointHoverBackgroundColor ||
66+
dataset.borderColor ||
67+
dataset.backgroundColor
68+
)
69+
return { backgroundColor }
70+
}
71+
}
5372
}
5473
}
5574
}

0 commit comments

Comments
 (0)