Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/plugins/plugin.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ function createTooltipItem(chart, item) {

return {
chart,
label,
// If label is an array (multiline), join with ', ' for tooltip display
label: isArray(label) ? label.join(', ') : label,
parsed: controller.getParsed(index),
raw: chart.data.datasets[datasetIndex].data[index],
formattedValue: value,
Expand Down
32 changes: 32 additions & 0 deletions test/specs/plugin.tooltip.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1948,4 +1948,36 @@ describe('Plugin.Tooltip', function() {
}]
}));
});

it('Should join multiline array labels with comma and space (issue #12049)', async function() {
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
label: 'Dataset 1',
data: [10, 20, 30],
}],
labels: [['Yellow', 'subTitle'], 'Point 2', 'Point 3']
},
options: {
plugins: {
tooltip: {
mode: 'index',
intersect: false,
}
}
}
});

var point = {
x: chart.chartArea.left + (chart.chartArea.right - chart.chartArea.left) / 6,
y: chart.chartArea.top + 5
};

var tooltip = chart.tooltip;
await jasmine.triggerMouseEvent(chart, 'mousemove', point);

// The title should show the label joined with ', ' not just ','
expect(tooltip.title).toEqual(['Yellow, subTitle']);
});
});