Skip to content
Related Articles

Related Articles

D3.js diverging.domain() Function
  • Last Updated : 31 Aug, 2020

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




<!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>

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.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>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :