The D3.js node.data property returns the original object from the data source for which the hierarchy node was created.
Syntax:
node.data
Return Value: This property returns the original object from the data source for which the hierarchy node was created.
Example 1: Getting the data object from the hierarchy node.
HTML
<!DOCTYPE html> < html > < head > Â Â Â Â < meta charset = "utf-8" > Â Â Â Â Â Â < script src = Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â < script > Â Â Â Â Â Â Â var data = {"name":"GFG1", "children":[ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {"name":"GFG2", }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {"name":"GFG3", "children":[ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {"name":"GFG4"}, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {"name":"GFG5"}]}, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {"name":"GFG6"}]}; Â Â Â Â Â Â Â Â Â Â var root = d3.hierarchy(data); Â Â Â Â Â Â Â Â console.log(root.data) Â Â Â Â </ script > </ body > Â Â </ html > |
Output:
Example 2:
HTML
<!DOCTYPE html> < html > < head >     < meta charset = "utf-8" >       < script src =     </ script > </ head >   < body >     < script >        var data = {             "name":"neveropen",             "about":"Computer Science Portal",             "children":[{"name":"GFG"}]           }         var root = d3.hierarchy(data);         console.log(root.data)     </ script > </ body >   </ html > |
Output: