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


d3.js band.step()用法及代碼示例

d3.js中的band.step()函數用於查找頻段的階躍,該階躍是通過查找相鄰頻段的起點之間的距離來計算的。

用法:

band.step()

參數:此函數不接受任何參數。

返回值:此函數返回相鄰頻段起點之間的距離。

範例1:



HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script src= 
"https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <script> 
        // Creating the band scale with  
        // specified domain and range 
        var A = d3.scaleBand() 
            .domain([10, 20, 30, 40, 50]) 
            .range([0, 10]); 
  
        // Using the step() function 
        let step_val = A.step(); 
  
        // Printing the Output   
        console.log("Step Of A:", step_val); 
    </script> 
</body> 
  
</html>

輸出:

Step Of A: 2

範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<head> 
    <script src= 
        "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <script> 
        // Creating the band scale with  
        // specified domain and range 
        var B = d3.scaleBand() 
            .domain(["one", "two", 
                "three", "four"]) 
            .range([0, 60]); 
  
        // Using the step() function 
        let step_val = B.step(); 
  
        // Printing the Output   
        console.log("Step in B:", step_val); 
    </script> 
</body> 
  
</html>

輸出:

Step in B: 15




相關用法


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