Skip to content
Related Articles

Related Articles

D3.js band.bandwidth() Function
  • Last Updated : 23 Sep, 2020

The band.bandwidth() function in d3.js is used to find the width of each band.

Syntax:

band.bandwidth()

Parameters: This function does not accept any parameter.

Return Values: This function returns the width of each band.

Example 1:



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Bandwith Of A:  2

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Bandwith Of each band in B:  15

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :