Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool Tip isn't displaying point data correctly #7839

Closed
PaulWieland opened this issue Oct 2, 2020 · 2 comments · Fixed by #8781
Closed

Tool Tip isn't displaying point data correctly #7839

PaulWieland opened this issue Oct 2, 2020 · 2 comments · Fixed by #8781

Comments

@PaulWieland
Copy link

image

image

Expected Behavior

The tool tip of a data point should show the x & y values of the data point.

Current Behavior

The tool tip's x value is being take from the series index number rather than from the data point x value.

Possible Solution

When a data set uses the point format type, the tooltip has to take the x/y coordinates from the point object rather than assuming that the point's index aligns with the x axis index.

Steps to Reproduce

Create an X axis label array with a few values, e.g. labels = ['January','February','March'].

Create a data series using format: 'point' and with the data having fewer points than the x axis labels, e.g. data = [{x: 'March', y: 10}]

Context

The wrong labels are being rendered.

Environment

  • Chart.js version: 2.9.3
  • Browser name and version: Safari & Chrome
  • Link to your project:
@kurkle
Copy link
Member

kurkle commented Oct 2, 2020

Its the title callback that fails:

title: function(tooltipItems, data) {
var title = '';
var labels = data.labels;
var labelCount = labels ? labels.length : 0;
if (tooltipItems.length > 0) {
var item = tooltipItems[0];
if (item.label) {
title = item.label;
} else if (item.xLabel) {
title = item.xLabel;
} else if (labelCount > 0 && item.index < labelCount) {
title = labels[item.index];
}
}
return title;
},

You can override that. This is most likely fixed in v3, too lazy to create a test from scratch.

@PaulWieland
Copy link
Author

Work around:

tooltips: {
	callbacks: {
		title: function(tooltipItem, data) {
			let dataSet = tooltipItem[0].datasetIndex;
			let index = tooltipItem[0].index;
			let title = data.datasets[dataSet].data[index].x;
			return title;
		}
	}
}

alessandroasm added a commit to alessandroasm/Chart.js that referenced this issue Oct 6, 2020
When using object datasets, labels are displayed incorrect because they are
retrieved based on item index instead of the corresponding x or y property.

Fixes chartjs#7839
alessandroasm added a commit to alessandroasm/Chart.js that referenced this issue Oct 6, 2020
When using object datasets, labels are displayed incorrect because they are
retrieved based on item index instead of the corresponding x or y property.

Fixes chartjs#7839
alessandroasm added a commit to alessandroasm/Chart.js that referenced this issue Oct 8, 2020
When using object datasets, labels are displayed incorrect because they are
retrieved based on item index instead of the corresponding x or y property.

Fixes chartjs#7839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants