Friday, September 5, 2025
HomeLanguagesJavascriptD3.js band.bandwidth() Function

D3.js band.bandwidth() Function

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




<!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 bandwidth() Function
        let gfg = A.bandwidth();
 
        // Printing the Output 
        console.log("Bandwidth Of A: ",gfg);
         
    </script>
</body>
 
</html>


Output:

Bandwidth Of A:  2

Example 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 bandwidth() Function
        let gfg = B.bandwidth();
 
        // Printing the Output 
        console.log("Bandwidth Of each band in B: ",gfg);
    </script>
</body>
 
</html>


 
 Output: 

Bandwidth Of each band in B:  15
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7028 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS