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


d3.js band.bandwidth()用法及代码示例


d3.js中的band.bandwidth()函数用于查找每个波段的宽度。

用法:

band.bandwidth()

参数:此函数不接受任何参数。

返回值:此函数返回每个波段的宽度。

范例1:



HTML

<!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 A = d3.scaleBand()  
                    .domain([10, 20, 30, 40, 50])  
                    .range([0, 10]);  
      
        // Applying bandwith() Function 
        let gfg = A.bandwidth(); 
  
        // Printing the Output   
        console.log("Bandwith Of A:",gfg);  
          
    </script>  
</body> 
  
</html>

输出:

Bandwith Of A: 2

范例2:

HTML

<!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 B = d3.scaleBand()  
                    .domain(["one", "two", "three", "four"])  
                    .range([0, 60]);  
      
        // Applying bandwith() Function 
        let gfg = B.bandwidth(); 
  
        // Printing the Output   
        console.log("Bandwith Of each band in B:",gfg);  
    </script>  
</body> 
  
</html>

输出:

Bandwith Of each band in B: 15




相关用法


注:本文由纯净天空筛选整理自jana_sayantan大神的英文原创作品 D3.js band.bandwidth() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。