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

