Open In App

D3.js scaleDiverging diverging() Function

Last Updated : 01 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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() function of d3.scaleDiverging() is used to return a value from the range that corresponds to the given input value that must lie in the specified domain.

Syntax:

diverging(value);

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

  • value: This takes a value from the specified domain.

Return Values: This function returns a value that corresponds to the default range.

Example:

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.scaleDivering | diverging() Function </h4>
    <script>
        var diverging = d3.scaleDiverging();
        // Default scale is identity function
  
        // Printing value using diverging() Function
        document.write("<p>diverging(0.2): ", 
                    diverging(0.2) + "</p>");
        document.write("<p>diverging(0.5): ", 
                    diverging(0.5) + "</p>");
    </script>
</body>
  
</html>


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads