Mouse Events
D3 supports all JavaScript mouse events. Learn how to detect hover events with D3.
We'll cover the following
We will use mouse events to help us detect when the reader is hovering over a dot. If they are, we are going to move the tooltip element above the dot. The contents of the tooltip will need to be updated to show the data joined to the dot.
Adding mouse events
A mouse event called mouseenter
can be used to detect when the mouse is hovering over an element. We will be using this event to help us create our UI. In the script section, search for the section in our code where we draw the dots.
At the end of this chain, we will add the on()
function to listen for the mouseenter
event.
Get hands-on with 1400+ tech skills courses.