当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。