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


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


band.round()函數用於將舍入設置為true或false,即啟用或禁用舍入。如果舍入為真,則每個頻段的開始和結束均為整數。

用法:

band.round([round]);

參數:此函數接受上麵給定和下麵描述的單個參數:

  • round:此參數接受布爾值true或false。

返回值:此函數不返回任何內容。

下麵給出的是上麵給出的函數的一些例子。



範例1:

<!DOCTYPE html>  
<html lang = "en">  
<head>  
    <meta charset = "UTF-8" />  
    <meta name = "viewport"
        path1tent = "width=device-width,  
        initial-scale = 1.0"/>  
    <script src = 
    "https://d3js.org/d3.v4.min.js"> 
    </script> 
      
</head>  
<body>  
    <script>  
    // Creating the band scale with 
    // specified domain and range. 
        var band = d3.scaleBand() 
          .domain([0.001, 0.002, 0.003, 0.004]) 
        // When range is in string 
                    .range(["0", "15"]); 
        
console.log("When round function is set to false:"); 
      // Setting round to false 
        band.round(false); 
        
        console.log("band(0.001):", band(0.001)); 
        console.log("band(0.002):", band(0.002)); 
    </script>  
</body>  
</html>

輸出:

範例2:

<!DOCTYPE html>  
<html lang = "en">  
<head>  
    <meta charset = "UTF-8" />  
    <meta name = "viewport"
        path1tent = "width=device-width,  
        initial-scale = 1.0"/>  
    <script src = 
    "https://d3js.org/d3.v4.min.js"> 
    </script> 
</head>  
<body>  
    <script>  
    // Creating the band scale with  
   //specified domain and range. 
        var band = d3.scaleBand() 
   .domain([0.001, 0.002, 0.003, 0.004]) 
        // When range is in string 
                    .range(["0", "15"]); 
        
 console.log("When round function is set to true:"); 
      // Setting round to true 
        band.round(true); 
        
        console.log("band(0.001):", band(0.001)); 
        console.log("band(0.002):", band(0.002)); 
    </script>  
</body>  
</html>

輸出:




相關用法


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