From c3e861d78c175579474352c9706b49e379a9a7db Mon Sep 17 00:00:00 2001 From: LeeLenaleee <39033624+LeeLenaleee@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:41:52 +0100 Subject: [PATCH] dataset tooltip now shows correctly (#8024) * dataset tooltip now shows correctly * removed optional chaining --- src/plugins/plugin.tooltip.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index c4fbb38c8..7a33d3967 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -1146,7 +1146,10 @@ export default { const item = tooltipItems[0]; const labels = item.chart.data.labels; const labelCount = labels ? labels.length : 0; - if (item.label) { + + if (this && this.options && this.options.mode === 'dataset') { + return item.dataset.label || ''; + } else if (item.label) { return item.label; } else if (labelCount > 0 && item.dataIndex < labelCount) { return labels[item.dataIndex]; @@ -1163,6 +1166,10 @@ export default { // Args are: (tooltipItem, data) beforeLabel: noop, label(tooltipItem) { + if (this && this.options && this.options.mode === 'dataset') { + return tooltipItem.label + ': ' + tooltipItem.formattedValue || tooltipItem.formattedValue; + } + let label = tooltipItem.dataset.label || ''; if (label) { -- 2.47.2