Sunday, September 22, 2024
Google search engine
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 =
    </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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments