Sunday, June 14, 2026
HomeLanguagesJavascriptD3.js arc.cornerRadius() Function

D3.js arc.cornerRadius() Function

The arc.cornerRadius() function is used to set the corner radius for rounded corners. If the radius is not specified, returns the current corner radius accessor, which defaults to:

function cornerRadius() {
    return 0;
}

Syntax:

arc.cornerRadius([radius]);

Parameters: This function accepts a single parameter as mentioned above and described below.

  • radius: This parameter takes a number that decides the radius of the corners.

Return Values: This function returns the arc generator.

Example 1:

HTML




<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport"
          content="width=device-width, 
                  initial-scale=1.0"/> 
      
    <!--Fetching from CDN of D3.js -->
    <script src= 
        "https://d3js.org/d3.v6.min.js"> 
    </script>
  
</head>
  
<body> 
    <div style="width:300px; height:300px;">
        <center>
  
            <h1 style="color:green">
                neveropen
            </h1> 
  
            <h2>
                arc.cornerRadius()
            </h2> 
        </center>
  
        <svg width="300" height="300">
        </svg>
    </div>
  
    <script> 
        var svg = d3.select("svg")
            .append("g")
            .attr("transform", "translate(150,200)");
  
        // An arc generator created
        var arc = d3.arc()
            .outerRadius(-5)
            .innerRadius(150)
            .startAngle(0)
            // Use of cornerRadius Function
            .cornerRadius(6666)
            .endAngle(1);
  
        svg.append("path")
            .attr("class", "arc")
            .attr("d", arc);
  
        let p = document.querySelector(".arc");
        p.style.fill="green";
    </script> 
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport"
          content="width=device-width, 
                  initial-scale=1.0"/> 
   
    <!--Fetching from CDN of D3.js -->
    <script src= 
        "https://d3js.org/d3.v6.min.js"> 
    </script>
  
</head>
  
<body> 
    <div style="width:300px; height:300px;">
        <center>
            <h1 style="color:green">
                neveropen
            </h1> 
  
            <h2>
                arc.cornerRadius()
            </h2> 
  
        </center>
  
        <svg width="300" height="300">
        </svg>
    </div>
  
    <script> 
        var svg = d3.select("svg")
            .append("g")
            .attr("transform", "translate(120,200)");
  
        // An arc generated
        var arc = d3.arc()
            .outerRadius(140)
            .innerRadius(200)
            .startAngle(0)
            // Use of cornerRadius Function
            .cornerRadius(20)
            .endAngle(1);
  
        svg.append("path")
            .attr("class", "arc")
            .attr("d", arc);
  
        let p = document.querySelector(".arc");
        p.style.fill="green";
    </script> 
</body> 
  
</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

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS