Related Articles

Related Articles

D3.js node.links() Function
  • Last Updated : 18 Sep, 2020

The node.links() function returns an array of links to the children of the node object, each link object has a source and a target field that hold references to child nodes.

Syntax:

node.links();

Parameters: This method does not accept any parameters.

Return Values: This method returns an array of links to the children of the node object.

Example 1:



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <script src=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {
            "name":"GeeksforGeeks", 
            "about":"Computer Science Portal",
            "children":[
                {"name":"GFG1"},
                {"name":"GFG2"},
                {"name":"GFG3"}
            ]
        }
        var root = d3.hierarchy(data);
        a=root.links();
        console.log(a);
        for (i=0;i<a.length;i++){
            console.log(a[i].source.children)
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: Root containing no children return empty links array.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <script src=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {"name":"GFG1"}
  
        var root = d3.hierarchy(data);
  
        console.log(root.links());
    </script>
</body>
  
</html>

chevron_right


Output:
 

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :