0
svg.append('circle')
    .attr('class', 'points')
    .attr("cx", d => x(d.date))
    .attr("cy", d => y(d.close))
    .attr("r", 10)
    .attr("fill", "#364652")
    .on('mouseover', (d, i) => {
          console.log(this)
     })

In the example above - this returns window, so d3.select(this) inside of that function is not working, like it did in v3 version examples.

How can i get element, that been hovered with the mouse?

Src
  • 5,252
  • 5
  • 28
  • 56

1 Answers1

0

I've just noticed that i'm using arrow function, so it binds context on creation.

If you want to get element that triggered event, you should use regular function expression:

svg.append('circle')
    .attr('class', 'points')
    .attr("cx", d => x(d.date))
    .attr("cy", d => y(d.close))
    .attr("r", 10)
    .attr("fill", "#364652")
    .on('mouseover', function (d, i) {
          console.log(this)
     })
Src
  • 5,252
  • 5
  • 28
  • 56