D3.js quantile.invertExtent() Function

The quantile.invertExtent() function in d3.js is used to return the extent of the values that are present in the specified domain for the corresponding value in the range.

Syntax:

quantile.invertExtent( value )

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

  • value: It is the value that corresponds to the specified range.

Return Values: This function returns a value from the specified domain.

Below programs illustrate the quantile.invertExtent() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src=
        "https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    "https://d3js.org/d3-interpolate.v1.min.js">
    </script>
    <script src=
    "https://d3js.org/d3-scale-chromatic.v1.min.js">
    </script>
</head>
  
<body>
    <h1 style="color: green;">
        w3wiki
    </h1>
  
    <p>quantile.invertExtent() Function </p>
  
    <script>
        var quantile = d3.scaleQuantile()
            // Setting domain for the scale.
            .domain([1, 10])
            // Setting the range of the scale.
            .range([0, 960]);
  
        // Printing the output
        document.write("<h3>" +
            quantile.invertExtent(960) +
            "</h3>");
        document.write("<h3>" +
            quantile.invertExtent(0) +
            "</h3>");
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src=
        "https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    "https://d3js.org/d3-interpolate.v1.min.js">
    </script>
    <script src=
    "https://d3js.org/d3-scale-chromatic.v1.min.js">
    </script>
</head>
  
<body>
    <h1 style="color: green;">
        w3wiki
    </h1>
  
    <p>quantile.invertExtent() Function </p>
  
    <script>
        var quantile = d3.scaleQuantile()
            // Setting domain for the scale.
            .domain([1, 10])
            // Setting the range of the scale.
            .range(["red", "blue", "orange"]);
  
        // Printing the output
        document.write(
            "<h3>quantile.invertExtent(\"blue\"): " +
            quantile.invertExtent("blue") + "</h3>");
        document.write(
            "<h3>quantile.invertExtent(\"red\"): " +
            quantile.invertExtent("red") + "</h3>");
    </script>
</body>
  
</html>


Output: