Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js threshold.range() Function

D3.js threshold.range() Function

The threshold.range() function is used to set the range of the threshold scale. The number of values in range array is always one greater than the domain array, if not then the behavior of the scale may be undefined.

Syntax:

threshold.range([range]);

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

  • range: This parameter accepts an array of discrete values. If there is “n” number of values in the domain, the range must have “n+1” number of values.

Return Value: This function does not return any value.

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>
    <h2 style="color:green;">neveropen</h2>
  
    <p>threshold.range() Function </p>
  
    <script>
        var threshold = d3.scaleThreshold()
  
            // Setting domain for the scale.
            .domain([10, 20, 30, 40])
  
            // Setting the range for the scale.
            // Number of elements is one more 
            // then domain array size.
            .range(["red", "blue", 
                "green", "yellow", "white"]);
  
        document.write("<h4>" 
            + threshold(10) + "</h4>");
              
        document.write("<h4>" 
            + threshold(20) + "</h4>");
    </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>
    <h2 style="color:green;">neveropen</h2>
  
    <p>threshold.range() Function </p>
  
    <script>
        var threshold = d3.scaleThreshold()
  
            // Setting domain for the scale.
            .domain([10, 20, 30, 40])
          
            // Setting the range for the scale.
            // Number of elements is one more 
            // then domain array size.
            .range([0.01, 0.02, 0.03, 0.04, 0.05]);
  
        document.write("<h4>" 
            + threshold(20) + "</h4>"); // 0.03
  
        document.write("<h4>" 
            + threshold(40) + "</h4>"); // 0.05
  
        // This value is outside the domain
        document.write("<h4>" 
            + threshold(500) + "</h4>"); // 0.05
    </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

Recent Comments