Friday, September 5, 2025
HomeLanguagesJavascriptD3.js scaleTime() Function

D3.js scaleTime() Function

The d3.scaleTime() function is used to create and return a new time scale which have the particular domain and range. In this function the clamping is disabled by default.

Syntax:

d3.scaleTime([[domain, ]range]);

Parameter: This function accepts two parameters as mentioned above and described below.

  • Domain: It is an array of integers that defines the extent of domain values. If not specified then the default value is [2000-01-01, 2000-01-02].
  • Range: It is an array of integers or string. If not specified then the default value is [0, 1].

Return Value: This function returns a function.

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>
    <h2 style="color:green">Geeks for neveropen</h2>
    <p>d3.scaleTime() Function</p>
    <script>
        var time = d3.scaleTime()
            .domain([1, 10])
            .range([10, 5]);
        document.write("<h3>Type of d3.scaleTime() is: "
            + typeof (time) + "</h3>");
              
        document.write("<h3>time(10): " 
            + time(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=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color:green;">Geeks for neveropen</h2>
    <p>d3.scaleTime() Function </p>
    <script>
        var time = d3.scaleTime()
            .domain([1, 10])
            .range([1, 100])
        document.write("<h3>time(1): " + time(1) + "</h3>")
        document.write("<h3>time(2): " + time(2) + "</h3>")
        document.write("<h3>time(3): " + time(3) + "</h3>")
        document.write("<h3>time(4): " + time(4) + "</h3>")
    </script>
</body>
  
</html>


Output:

RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS