Open In App

D3.js scaleTime time() Function

Last Updated : 26 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The time() function of d3.scaleTime() is used to return a value from and within the given range from the specified domain.

Syntax:

time(value)

Parameter: This function accepts only one parameter as mentioned above and described below.

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

Return Value: This function returns a value from the range.

Below example illustrates the scaleTime time() function in D3.js:

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.v4.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color:green;">Geeks for geeks</h2>
  
    <p>d3.scaleTime() | time() Function </p>
      
    <script>
        var time = d3.scaleTime()
            .domain([1, 100])
            .range([1, 100])
        document.write("<h3>The value of time(10): "
                    + time(10) + "</h3>")
        document.write("<h3>The value of time(20): "
                    + time(20) + "</h3>")
        document.write("<h3>The value of time(30): " 
                    + time(30) + "</h3>")
        document.write("<h3>The value of time(40): " 
                    + time(40) + "</h3>")
    </script>
</body>
  
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads