當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


d3.js arc.cornerRadius()用法及代碼示例

arc.cornerRadius()函數用於設置圓角的拐角半徑。如果半徑未指定,則返回當前角半徑訪問器,其中默認值至:

function cornerRadius() {
    return 0;
}

用法:

arc.cornerRadius([radius]);

參數:該函數接受如上所述和以下描述的單個參數。

  • radius:此參數采用一個數字,該數字確定角的半徑。

返回值:這個函數返回電弧發生器

範例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"> 
                GeeksforGeeks 
            </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>

輸出:

範例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"> 
                GeeksforGeeks 
            </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>

輸出:




相關用法


注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js arc.cornerRadius() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。