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

Scatter plot with 2 data sets, hover behaviour for one data point also happens with a data point in the second data set #8350

Closed
chrisjdavie opened this issue Jan 28, 2021 · 4 comments · Fixed by #8354

Comments

@chrisjdavie
Copy link

https://codepen.io/chrisjdavie/pen/RwobexW

Expected Behavior

In a scatter plot with 2 data sets, when hovering cursor over data point the hover behaviour should be for that single point, and the label showing the data points should be for that single point as well.

Current Behavior

When hovering over a data point, the hover behaviour happens for that data point and the corresponding data point in the second data set. The label is halfway between those two data points, and has the data for both points on it.

Possible Solution

Steps to Reproduce

https://codepen.io/chrisjdavie/pen/RwobexW

Hover the cursor over a data point. (using https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.0.0-beta.9/chart.min.js. Also tested with latest master on one of the sample charts)

Context

I am trying to plot a scatter plot with two data sets, where you can hover a cursor over a point, and have the data displayed as a label.

Environment

  • Chart.js version: Chart.js 3.0.0 beta 9
  • Browser name and version: Mozilla Firefox 84.0.2, Google Chrome 88.0.4324.96 (Official Build) (64-bit)

(Thanks for looking at this, I'm really enjoying using Chart.js, charting is straightforward, once I figure out how to do things in JS)

@kurkle
Copy link
Member

kurkle commented Jan 28, 2021

Did you try setting a mode for interactions?
https://www.chartjs.org/docs/master/general/interactions/modes/

@chrisjdavie
Copy link
Author

Thanks, that fixed it. I hadn't tried, didn't see that in the docs - looks like it's an issue with the 'index' mode, 'nearest' and 'point' seem to do what I'd expect

@etimberg
Copy link
Member

I think the scatter chart is inheriting the line defaults which use index mode. If there's a time to change the default mode, it's now before v3 releases

@chrisjdavie
Copy link
Author

That makes sense - seems a sensible default for line charts with multiple datasets, but it isn't how I'd expect scatter charts to behave in the multiple dataset case, personally at least

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.

3 participants