Saturday, October 25, 2025
HomeLanguagesJavascriptD3.js bandScale band() Function

D3.js bandScale band() Function

The band() function in d3.js library is used to return a start of the band from the range corresponding to the given input domain.

Syntax:

band(value);

Parameters: This function takes a single parameter as given above and described below.

  • Value: This accepts a value from the specified domain.

Return Value: This function returns a value from the specified range.

Example: The following example demonstrates the above function.

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>
        // Create the band scale with 
        // specified domain and range.
        var band = d3.scaleBand()
            .domain([0, 1, 2, 3, 4, 5])
            .range([1, 10]);
              
        // Discrete values are automatically 
        // created by the band function
        // band of the range is [1, 10]
        console.log("band(0): ", band(0));
        console.log("band(1): ", band(1));
        console.log("band(2): ", band(2));
        console.log("band(3): ", band(3));
    </script>
</body>
  
</html>


Output:

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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS