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


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

arc.centroid()函數用於計算圓弧中心線的中點。使用(startAngle + endAngle)/2和(innerRadius + outerRadius)/2計算生成的中點。

用法:

arc.centroid(arguments);

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

  • arguments:這些是任意參數。

返回值:此函數返回包含點的數組。

範例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> 
    <script>  
  
        // Creating an arc 
        var arc = d3.arc() 
            .innerRadius(40) 
            .outerRadius(45) 
            .startAngle(10) 
            .endAngle(8); 
  
        // arc.centroid function  
        console.log(arc.centroid()); 
    </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> 
    <script>  
  
        // Creating an arc 
        var arc = d3.arc() 
            .innerRadius(40) 
            .outerRadius(45) 
            .startAngle(0) 
            .endAngle(8); 
        // arc.centroid function  
        console.log("Change in start and end angle"); 
        console.log("will change the centroid"); 
        console.log(arc.centroid()); 
    </script>  
</body> 
   
</html>

輸出:




相關用法


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