D3.js node.data Property
Last Updated :
23 Sep, 2020
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":"GeeksforGeeks",
"about":"Computer Science Portal",
"children":[{"name":"GFG"}]
}
var root = d3.hierarchy(data);
console.log(root.data)
</ script >
</ body >
</ html >
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...