Saturday, January 17, 2026
HomeLanguagesJavascriptD3.js time.invert() Function

D3.js time.invert() Function

The time.invert() function is used to return a value from the domain when given a input value from the specified range. This inversion can be useful in determining the data value corresponding to the position of the mouse.

Syntax:

time.invert(value)

Parameters: This function accepts only one parameter as given above and described below.

  • Value: This parameter accepts a value from the specified range.

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

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.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color:green;">
        neveropen
    </h1>
      
    <p>D3.js time.invert() Function</p>
  
    <script>
        var time = d3.scaleTime()
            .domain([2011 - 01 - 01, 2015 - 05 - 02])
            .range([1, 10])
  
        document.write("<h3>time(10): " 
                    + time(10) + "</h3>")
  
        document.write("<h3>time.invert(10): " 
                    + time.invert(10) + "</h3>")
  
        document.write("<h3>time(time.invert(10)): " 
                + time(time.invert(10)) + "</h3>")
    </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.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;">
        neveropen
    </h1>
  
    <p>D3.js time.invert() Function </p>
  
    <script>
        var time = d3.scaleTime()
            .domain([1, 100])
            .range([1, 10])
  
        document.write("<h3>The value of time(time.invert(1)):"
            + time(time.invert(1)) + "</h3>")
        document.write("<h3>The value of time(time.invert(2)):"
            + time(time.invert(2)) + "</h3> ")
        document.write("<h3>The value of time(time.invert(3)):"
            + time(time.invert(3)) + "</h3> ")
        document.write("<h3>The value of time(time.invert(4)):"
            + time(time.invert(4)) + "</h3> ")
    </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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS