-2

Here is my code

I'm trying to get the selection name and cannot find the substitute for d3.select(this.parentNode).datum().key as used in this example

.on("mouseover", (d, i, nodes) => {
    const subgroupName = d3.select(nodes).datum().key; //d3.select(this.parentNode).datum().key;
    console.log(subgroupName);
  })

I tried using the 3rd node param in the mouse over function but not able to get the key and index in datum()

this.prentNode selects the top g however nodes are the rect inside the g. trying to find way to select the g element

How to get the selection key from data

1Mayur
  • 3,419
  • 5
  • 40
  • 64
  • I'm getting blank screen from the CodeSandbox. Also, `d3.select(this)` should get you the `rect` object that should have a key and index. – Ryan Morton Sep 16 '19 at 21:29

1 Answers1

-1
d3.select(nodes[i].parentNode).datum().key

this solved the problem for me as nodes[i] would be considered as this.

1Mayur
  • 3,419
  • 5
  • 40
  • 64