D3.js hierarchy() Function Last Updated : 23 Sep, 2020 Improve Improve Like Article Like Save Share Report 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 src="https://d3js.org/d3.v4.min.js"> </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 src="https://d3js.org/d3.v4.min.js"> </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: Like Article Suggest improvement Next D3.js interrupt() Function Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Explain the concept of scope hierarchy Explain the concept of the CSS Specificity Hierarchy How to use portals for rendering content outside the parent DOM hierarchy? How to get the function name from within that function using JavaScript ? How to get the function name inside a function in PHP ? 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 ? Like T tarun007 Follow Article Tags : D3.js JavaScript Web Technologies