D3.js diverging.domain() Function

The diverging scales are very much similar to continuous scales. The only difference is that the output range of this scale is fixed by the interpolator thus the range is not configurable.

The diverging.domain() function is used to set the domain of the scale. The domain array must take three numeric values.

Syntax:

diverging.domain([domain]);

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

  • domain: This is an array that takes three numeric values. The default domain of the scale is [0, 0.5, 1].

Return Values: This function does not return anything.



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.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4> D3.js | diverging.domain() Function </h4>
  
    <script>
        var diverging = d3.scaleDiverging()
  
            // Setting domain of the scale
            .domain([4, 0.001, 100]);
          
        document.write("<p>diverging(1): ", 
                diverging(1) + "</p>");
  
        document.write("<p>diverging(2): ", 
                diverging(2) + "</p>");
    </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.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4> D3.js | diverging.domain() Function </h4>
  
    <script>
        var diverging = d3.scaleDiverging();
        // Default scale is identity function
  
        document.write("<p>diverging(10): ", 
                    diverging(10) + "</p>");
  
        document.write("<p>diverging(200): ", 
                    diverging(200) + "</p>");
    </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.