D3.js threshold.domain() Function

The threshold.domain() function is used to set the domain of the threshold scale. The values given in this must be in non-descending order, if not then the behavior of the scale is undefined.

Syntax:

threshold.domain([domain]);

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

  • domain: This parameter accepts an array of elements in a sorted order which sets the domain of the scale.

Return Value: This function does not return any value.

Below programs illustrate the threshold.domain() function in D3.js



Example 1:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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;">GeeksforGeeks</h2>
  
    <p>threshold.domain() Function</p>
  
    <script>
        var threshold = d3.scaleThreshold()
          
            // Setting domain for the scale.
            .domain([1, 2, 3, 4])
            .range([10, 20, 30, 40, 50]);
        let val1 = threshold(1);
        let val2 = threshold(2);
        let val3 = threshold(4);
        document.write("<h4>" + val1 + "</h4>");
        document.write("<h4>" + val2 + "</h4>");
        document.write("<h4>" + val3 + "</h4>");
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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;">GeeksforGeeks</h2>
  
    <p>threshold.domain() Function </p>
  
    <script>
        var threshold = d3.scaleThreshold()
          
            // Setting domain for the scale.
            .domain([1, 2, 3, 4]);
        document.write("<h4>" + threshold(0) + "</h4>");
        document.write("<h4>" + threshold(4) + "</h4>");
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.