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

1 COMMENT

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS