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 > < 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 > < 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: