Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js lineRadial.radius() method

D3.js lineRadial.radius() method

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

Syntax:

d3.lineRadial.radius(radius);

Parameters:

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

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

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




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>D3.js | d3.lineRadial.radius()</title>
</head>
<script src=
</script>
<script src="https://d3js.org/d3.v4.min.js"></script
<body>
    <h1 style="text-align: center; color: green;">
        neveropen
    </h1>
  <center>
    <svg id="gfg" width="200" height="200">
    <g transform="translate(100, 100)"></g>
</svg>
</center>
    
</body>
<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>   
</html>


Output:

Example 2: getting the function for the radius.




<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
  <title>D3.js | d3.lineRadial.radius()</title>
</head>
<script src=
</script>
<script src="https://d3js.org/d3.v4.min.js"></script
<body>
    <h1 style="text-align: center; color: green;">
         neveropen
      </h1>
  <center>
    <svg id="gfg" width="200" height="200">
    <g transform="translate(100, 100)"></g>
</svg>
</center>
    
</body>
<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.radius());
console.log(lineRadialGenerator.radius);
</script>   
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments