Thursday, September 4, 2025
HomeLanguagesJavascriptD3.js band.domain() Function

D3.js band.domain() Function

The band.domain() function in d3.js is used to set the domain of the scale. The first value that is present in the domain will be mapped to the first band in the range array and so on.

Syntax:

band.domain([domain]);

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

  • domain: This parameter sets the domain of the scale i.e the minimum and the maximum value.

Return Values: This function does not return anything.

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> 
      // Create band scale with domain
      // and range
      var band = d3.scaleBand()
  
      // Setting domain for the scale
      .domain(["redcolor", "greencolor",
             "blackcolor", "bluecolor"]);
  
      console.log("band(redcolor): ",
              band("redcolor"));
      console.log("band(blackcolor): ",
              band("blackcolor"));
      console.log("band(greencolor): ",
              band("greencolor"));
      console.log("band(bluecolor): ", 
              band("bluecolor"));                        
    </script> 
</body> 
</html>


Output:

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 band = d3.scaleBand()
  
        // Setting domain for the scale
                 .domain([10, 20, 30, 40])
                 .range([0, 11]);
  
        console.log("band(10): ", band(10));
        console.log("band(20): ", band(20));
        console.log("band(30): ", band(30));
        console.log("band(40): ", band(40));
    </script> 
</body> 
</html>


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS