D3.js lineRadial.angle() Method

The d3.lineRadial.angle() method is a radial line accessor method. It sets or returns the angle accessor. If the angle is provided, it must be a number or a function that returns a number representing an angle in radians.

Syntax:

d3.lineRadial.angle( angle );

Parameters:

  • angle: This method takes an angle that can be a number or a function returning the angle.

Return Value: This method returns the angle accessor of the Radial line.

Example 1: Setting the angle using this method. For setting radius, we have used lineRadial.radius() method.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <script src=
    </script>
    <script src=
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <h1 style="text-align:center; color:green;">
        GeeksforGeeks
    </h1>
      
    <center>
        <svg id="gfg" width="200" height="200">
            <g transform="translate(100,100)"></g>
        </svg>
    </center>
  
    <script>
        var lineRadialGenerator = d3.lineRadial();
        var data = [
            { angle: 0, radius: 10 },
            { angle: 3.14 * .5, radius: 35 },
            { angle: 3.14 * .75, radius: 55 },
            { angle: 3.14, radius: 60 },
            { angle: 3.14 * 1.25, radius: 65 },
            { angle: 3.14 * 1.5, radius: 70 },
            { angle: 3.14 * 1.75, radius: 75 },
            { angle: 3.14 * 2, radius: 80 },
            { angle: 3.14 * 2.25, radius: 85 },
            { angle: 3.14 * 2.5, radius: 90 },
            { angle: 3.14 * 2.75, radius: 95 },
            { angle: 3.14 * 3, radius: 100 },
            { angle: 3.14 * 3.25, radius: 105 },
            { angle: 3.14 * 3.5, radius: 110 }
        ];
  
        var lineRadialGenerator = d3.lineRadial()
            .angle((d) => d.angle)
            .radius((d) => d.radius);
  
        d3.select("#gfg")
            .select("g")
            .append("path")
            .attr("d", lineRadialGenerator(data))
            .attr("fill", "none")
            .attr("stroke", "green");
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: Getting the function for the angle.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <script src=
    </script>
    <script src=
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <h1 style="text-align:center; color:green;">
        GeeksforGeeks
    </h1>
      
    <center>
        <svg id="gfg" width="200" height="200">
            <g transform="translate(100,100)"></g>
        </svg>
    </center>
  
    <script>
        var lineRadialGenerator = d3.lineRadial();
        var data = [
            { angle: 0, radius: 10 },
            { angle: 3.14 * .5, radius: 35 },
            { angle: 3.14 * .75, radius: 55 },
            { angle: 3.14, radius: 60 },
            { angle: 3.14 * 1.25, radius: 65 },
            { angle: 3.14 * 1.5, radius: 70 },
            { angle: 3.14 * 1.75, radius: 75 },
            { angle: 3.14 * 2, radius: 80 },
            { angle: 3.14 * 2.25, radius: 85 },
            { angle: 3.14 * 2.5, radius: 90 },
            { angle: 3.14 * 2.75, radius: 95 },
            { angle: 3.14 * 3, radius: 100 },
            { angle: 3.14 * 3.25, radius: 105 },
            { angle: 3.14 * 3.5, radius: 110 }
        ];
  
        var lineRadialGenerator = d3.lineRadial()
            .angle((d) => d.angle)
            .radius((d) => d.radius);
  
        d3.select("#gfg")
            .select("g")
            .append("path")
            .attr("d", lineRadialGenerator(data))
            .attr("fill", "none")
            .attr("stroke", "green");
  
        console.log(lineRadialGenerator.angle());
        console.log(lineRadialGenerator.angle);
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.