Saturday, February 7, 2026
HomeLanguagesJavascriptD3.js threshold.invertExtent() Function

D3.js threshold.invertExtent() Function

The threshold.invertExtent() function in d3.js is used to return the extent of the values in the specified domain.

Syntax:

threshold.invertExtent(value);

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

  • value: This parameter takes a value from the given range.

Return Values: This function returns a value from the domain corresponding to the given input value.

Below given are a few examples of the function given above.

Example 1:




<!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> 
    <script src=
    </script> 
    <script src=
    </script> 
    <script src=
    </script> 
</head> 
<body> 
    <h2 style="color:green;">Geeks for neveropen</h2>
    <p>threshold.invertExtent() Function </p>
    <script> 
        var threshold = d3.scaleThreshold()
                    // Setting domain for the scale.
                    .domain([1, 2, 3, 4])
                    .range(["red", "green", "blue"]);
        let val1=threshold.invertExtent("green");
        let val2=threshold.invertExtent("blue");
        document.write("<h4>["+val1+"]</h4>");
        document.write("<h4>["+val2+"]</h4>");
    </script> 
</body> 
</html>


Output:

Example 2:




<!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> 
    <script src=
    </script> 
    <script src=
    </script> 
    <script src=
    </script> 
</head> 
<body> 
    <h2 style="color:green;">Geeks for neveropen</h2>
    <p>threshold.invertExtent() 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.invertExtent(10);
        let val2=threshold.invertExtent(50);
        let val3=threshold.invertExtent(20);
        document.write("<h4>["+val1+"]</h4>");
        document.write("<h4>["+val2+"]</h4>");
        document.write("<h4>["+val3+"]</h4>");
    </script> 
</body> 
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32493 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6864 POSTS0 COMMENTS
Nicole Veronica
11990 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12083 POSTS0 COMMENTS
Shaida Kate Naidoo
7000 POSTS0 COMMENTS
Ted Musemwa
7241 POSTS0 COMMENTS
Thapelo Manthata
6951 POSTS0 COMMENTS
Umr Jansen
6936 POSTS0 COMMENTS