From: LeeLenaleee <39033624+LeeLenaleee@users.noreply.github.com> Date: Sun, 8 Nov 2020 20:41:52 +0000 (+0100) Subject: dataset tooltip now shows correctly (#8024) X-Git-Tag: v3.0.0-beta.7~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3e861d78c175579474352c9706b49e379a9a7db;p=thirdparty%2FChart.js.git dataset tooltip now shows correctly (#8024) * dataset tooltip now shows correctly * removed optional chaining --- 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) {