Thursday, April 2, 2026
HomeLanguagesJavascriptD3.js band.rangeRound() Function

D3.js band.rangeRound() Function

The band.rangeRound() function is used to set the range of the scale to the specified two-element array along with this it also set the round to true.

Syntax:

band.rangeRound([range]) 

Parameters: This function accepts single parameters as given above and described below:

  • range: This parameter accepts a two-element array of numbers.

Return Values: This function does not return anything.

Below given are a few examples of the function given above.

Example 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([10, 20, 30, 40, 50])
                    .range([0, 1]);
  
        console.log("Without rangeRound function:");
        console.log("band(10): ", band(10));
        console.log("band(20): ", band(20));
        
        console.log("With rangeRound function:");
        
        var band = d3.scaleBand()
                    .domain([10, 20, 30, 40, 50])
                    .rangeRound([0, 1]);
        
        console.log("band(10): ", band(10));
        console.log("band(20): ", band(20));
    </script> 
</body> 
</html>


Output:

Example 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([1, 2, 3, 4])
        // When range is in string
                    .range(["0", "10"]);
        console.log("Without rangeRound function:");
        console.log("band(1): ", band(1));
        console.log("band(2): ", band(2));
        
        console.log("With rangeRound function:");
        
        var band = d3.scaleBand()
                    .domain([1, 2, 3, 4, 5])
                    .rangeRound(["0", "10"]);
        
        console.log("band(1): ", band(1));
        console.log("band(2): ", band(2));
    </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
32512 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6885 POSTS0 COMMENTS
Nicole Veronica
12006 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12100 POSTS0 COMMENTS
Shaida Kate Naidoo
7015 POSTS0 COMMENTS
Ted Musemwa
7259 POSTS0 COMMENTS
Thapelo Manthata
6971 POSTS0 COMMENTS
Umr Jansen
6960 POSTS0 COMMENTS