Friday, November 14, 2025
HomeLanguagesJavascriptD3.js time.copy() Function

D3.js time.copy() Function

The time.copy() function in D3.js is used to construct and return the copy of the original scale. Changes done to the original scale will not affect the copy scale and vice-versa.

Syntax:

time.copy()

Parameters: This function does not accept any parameter.

Return Values: This function returns the copy of the original scale.

Below programs illustrate the time.copy() function in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <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>time.copy() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
  
            // Setting domain and range
            // for the scale
            .domain([1, 100])
            .range([1, 10]);
  
        // Creating a copy of the scale
        var copy = time.copy();
  
        document.write("<h3>time(1): " +
            time(1) + "</h3>");
        document.write("<h3>time(100): " +
            time(100) + "</h3>");
        document.write("<p> copy scale: </p>");
          
    document.write("<h3>copy(100): " +
            copy(100) + "</h3>");
        document.write("<h3>copy(1): " +
            copy(1) + "</h3>");
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <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>time.copy() Function </p>
  
    <script>
  
        var time = d3.scaleTime()
  
            // Setting domain and range
            // for the scale.
            .domain([1, 100])
            .range([1, 10]);
  
        // Creating a copy of the scale
        var copy = time.copy();
  
        document.write("<h3>time(1000): " +
            time(1000) + "</h3>");
        document.write("<h3>time(100000): " +
            time(10000) + "</h3>");
  
        // Using clamp on the copy of the scale
        document.write(
    "<p> copy scale with clamp function.</p>");
      
        copy.clamp(true);
        document.write("<h3>copy(1000): " +
            copy(1000) + "</h3>");
        document.write("<h3>copy(10000): " +
            copy(10000) + "</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!
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS