]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
dataset tooltip now shows correctly (#8024)
authorLeeLenaleee <39033624+LeeLenaleee@users.noreply.github.com>
Sun, 8 Nov 2020 20:41:52 +0000 (21:41 +0100)
committerGitHub <noreply@github.com>
Sun, 8 Nov 2020 20:41:52 +0000 (15:41 -0500)
* dataset tooltip now shows correctly

* removed optional chaining

src/plugins/plugin.tooltip.js

index c4fbb38c8cc270cb2a756e37e495567ad9981bfb..7a33d39676d027aca729598ddda1e2bb52b90edb 100644 (file)
@@ -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) {