Saturday, September 6, 2025
HomeLanguagesJavascriptD3.js | d3.continuous.invert() Function

D3.js | d3.continuous.invert() Function

The d3.continuous.invert() function in D3.js is used to return the corresponding value from the domain if a value from the range is given.

Syntax:

.invert( Value )

Parameters: This function accepts single parameter Value which holds the value of range.

Return Value: This function returns the corresponding value from the domain if a value from the range is given.

Below programs illustrate the d3.continuous.invert() function in D3.js:

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        D3.js | d3.continuous.invert() Function
    </title>
      
    <script src = 
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
          
        // Calling scaleLinear() function
        var x = d3.scaleLinear().domain([10, 150])
                    .range([0, 1000]);
  
        // Calling the .invert() function
        // and getting the corresponding value
        // from domain if value from range is given
        console.log(x.invert(150)); 
        console.log(x.invert(999));
    </script>
</body>
  
</html>


Output:

31
149.86

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        D3.js | d3.continuous.invert() Function
    </title>
      
    <script src = 
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
          
        // Calling scaleLinear() function
        var x = d3.scaleLinear().domain([0, 1])
                .range([10, 20]);
  
        // Calling the .invert() function
        // and getting the corresponding value
        // from domain if value from range is given
        console.log(x.invert(11)); 
        console.log(x.invert(13));
        console.log(x.invert(15)); 
        console.log(x.invert(19));
          
    </script>
</body>
</html>    


Output:

0.1
0.3
0.5
0.9

Reference: https://devdocs.io/d3~5/d3-scale#continuous_invert

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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS