D3.js hierarchy() Function

The d3.hierarchy() function in D3.js library is used to construct a root node data from a given hierarchical data. The data that is given must be of an object and must represent a root node.
Syntax:
d3.hierarchy(data[, children]);
Parameters: This function takes a single parameter as given above and described below.
- data: This parameter is an object of representing hierarchical data.
Return Value: This function return an object.
Below given are a few examples of the function given above.
Example 1:
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent= "width=device-width, initial-scale = 1.0"/> </script> </head> <body> <script> var obj = d3.hierarchy({ name: "rootNode", children: [ { name: "child1" }, { name: "child2", children: [ { name: "grandChild1" }, { name: "grandChild2" }, { name: "grandChild3" }, { name: "grandChild4" } ] }, { name: "child3", children: [ { name: "grandChild5" }, { name: "grandChild6" }, ] } ] }); console.log(obj); </script> </body> </html> |
Output:
Example 2:
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent= "width=device-width, initial-scale = 1.0"/> </script> </head> <body> <script> var obj = d3.hierarchy({ name: "rootNode", children: [ { name: "child1" }, { name: "child2", children: [ { name: "grandChild1" }, ] } ] }); console.log(obj); console.log(obj.data); console.log(obj.data.children[0]); </script> </body> </html> |
Output:
<!–
–>

How to get the function name from within that function using JavaScript ?

How to call a function that return another function in JavaScript ?

How to Check a Function is a Generator Function or not using JavaScript ?

How to implement a function that enable another function after specified time using JavaScript ?

How to create a function that invokes function with partials appended to the arguments in JavaScript ?

How to create a function that invokes the provided function with its arguments transformed in JavaScript ?

How to create a function that invokes each provided function with the arguments it receives using JavaScript ?

How to create a function that invokes function with partials prepended arguments in JavaScript ?

Difference between ‘function declaration’ and ‘function expression’ in JavaScript

Difference between Function.prototype.apply and Function.prototype.call



Please Login to comment…