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

Event handlers on pie charts? #199

Closed
erosenberg opened this issue Nov 15, 2017 · 5 comments
Closed

Event handlers on pie charts? #199

erosenberg opened this issue Nov 15, 2017 · 5 comments

Comments

@erosenberg
Copy link

Hello, just wanted to know if it's possible to add event handlers to pie charts. Essentially, I want a label elsewhere on my page to update when I hover over a specific data set. Is this possible? I can work around it, but it would be nice functionality to have if not there already. #

@erosenberg erosenberg changed the title Event Handlers on Pie charts? Event handlers on pie charts? Nov 15, 2017
@hshoff
Copy link
Member

hshoff commented Nov 16, 2017

Hi @erosenberg, thanks for checking out vx! Yes, events on a pie chart are possible.

vx-pie-events

demo: https://codesandbox.io/s/mjp8lmvop?expanddevtools=1

the important bit:

<Pie
  // ...
  onMouseEnter={data => event => {
    console.log("mouse enter", data.data.letter);
  }}
/>

@hshoff hshoff closed this as completed Nov 16, 2017
@erosenberg
Copy link
Author

This worked excellently. Thanks, @hshoff ! Was that that somewhere in the docs and I just missed it?
Also, amazing job on this and thanks again for the speedy response!

@libnine
Copy link

libnine commented Apr 14, 2020

Any possibility we can get an updated example? I'm trying to do exactly as above but my onMouseEnter function can't seem to grab the section it hovers over. Ultimately, i'm trying to implement a tooltip with the underlying data.

Here's a demo: https://codesandbox.io/s/jolly-burnell-uxzh7?file=/src/App.js

@hshoff
Copy link
Member

hshoff commented Apr 14, 2020

@libnine sure thing, here ya go: https://codesandbox.io/s/strange-lehmann-vdoff?file=/src/App.js

@libnine
Copy link

libnine commented Apr 14, 2020

Thank you so much Harrison!

adamdoe added a commit to CDCgov/cdc-open-viz that referenced this issue Oct 13, 2023
References:
https://codesandbox.io/s/mjp8lmvop?expanddevtools=1&file=/index.js
airbnb/visx#199

Notes:
- Tested using data => event => function pattern without any luck on <Pie /> component.
- Ended up using useEffect with setTimeout to hide the tooltips.
- Moved useIntersectionObserver to hooks folder
- Changed legend item classes to use an array and placed the legend text as a class
adamdoe added a commit to CDCgov/cdc-open-viz that referenced this issue Oct 13, 2023
References:
https://codesandbox.io/s/mjp8lmvop?expanddevtools=1&file=/index.js
airbnb/visx#199

Notes:
- Tested using data => event => function pattern without any luck on <Pie /> component.
- Ended up using useEffect with setTimeout to hide the tooltips.
- Moved useIntersectionObserver to hooks folder
- Changed legend item classes to use an array and placed the legend text as a class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants