Thursday, November 20, 2025
HomeLanguagesJavascriptD3.js sequential.copy() Function

D3.js sequential.copy() Function

The sequential.copy() function in D3.js is used to construct and return a copy of the original scale. Any changes in original scale will not affect the copy scale and vice-versa. Sequential scales are similar to continuous scales. In a continuous scale, mapping is done in a continuous way between domain and range. The only difference is that the output range of this scale is fixed by its interpolator and this range cannot be changed.

Syntax:

sequential.copy()

Parameters: This function does not accept any parameters.

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

Below given are a few examples of sequential.copy() in D3.js:

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green">
        neveropen
    </h2>
  
    <h4> D3.js | sequential.copy() Function </h4>
      
    <script>
        var sequential = d3.scaleSequential();
  
        // Default scale is identity function
        document.write("<h4>From original scale:</h4>")
  
        document.write("<p>sequential(0.2): ", 
                    sequential(0.2) + "</p>");
          
        document.write("<p>sequential(0.5): ", 
                    sequential(0.5) + "</p>");
  
        // Creating copy of the original scale
        var sequentialCopy = sequential.copy();
        document.write("<h4>From copy scale:</h4>")
        document.write("<p>sequentialCopy(0.2): ", 
                    sequentialCopy(0.2) + "</p>");
  
        document.write("<p>sequentialCopy(0.5): ", 
                    sequentialCopy(0.5) + "</p>");
    </script>
</body>
  
</html>


Output:

Example 2: Any change in the copy scale does not affect the original scale.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://d3js.org/d3.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green">
        neveropen
    </h2>
  
    <h4> D3.js | sequential.copy() Function </h4>
  
    <script>
        var sequential = d3.scaleSequential();
  
        // Default scale is identity function
        document.write("<h4>From original scale:</h4>");
  
        document.write("<p>sequential(0.4): ", 
                    sequential(0.4) + "</p>");
        document.write("<p>sequential(0.6): ", 
                    sequential(0.6) + "</p>");
  
        // Creating copy of the original scale
        var sequentialCopy = sequential.copy();
        sequentialCopy.domain([1, 2]);
        document.write(
        "<h4>From copy scale after changing domain:</h4>");
  
        document.write("<p>sequentialCopy(0.4): ", 
                    sequentialCopy(0.4) + "</p>");
        document.write("<p>sequentialCopy(0.6): ", 
                    sequentialCopy(0.6) + "</p>");
    </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
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS