Friday, December 12, 2025
HomeLanguagesJavascriptD3.js quantile.copy() Function

D3.js quantile.copy() Function

The quantile.copy() function returns the exact copy of the original scale. Any changes if made in either of the scale will not affect the other scale.

Syntax:

quantile.copy();

Parameters: This function does not accept any parameter.

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

Below examples illustrate the quantile.copy() function in D3.js:

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>
</head>
  
<body>
    <h2 style="color:green;">GeekforGeeks</h2>
  
    <p>quantile.copy() Function</p>
  
    <script>
        var quantile = d3.scaleQuantile()
            // Setting domain for the scale.
            .domain([1, 2, 15, 19])
            // Discrete range
            .range(["red", "green", "black", "blue"]);
        // Printing the output.
        document.write("<h3>Form original scale: </h3>");
  
        document.write("<span>quantile(1): " 
                + quantile(1) + "</span><br>");
        document.write("<span>quantile(15): " 
                + quantile(15) + "</span><br>");
        document.write("<h3>Form copy scale: </h3>");
        var copyscale = quantile.copy();
        document.write("<span>copyscale(1): " 
                + copyscale(1) + "</span><br>");
        document.write("<span>copyscale(15): "
                + copyscale(15) + "</span><br>");
    </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>
</head>
  
<body>
    <h2 style="color: green;">GeekforGeeks</h2>
  
    <p>quantile.copy() Function </p>
  
    <script>
        var quantile = d3.scaleQuantile()
            // Setting domain for the scale.
            .domain([1, 2, 15, 19])
            // Discrete range
            .range(["red", "green", "black", "blue"]);
  
        // Printing the output.
        document.write("<h3>Form original scale: </h3>");
        document.write("<span>quantile(2): " 
                + quantile(2) + "</span><br>");
        document.write("<span>quantile(19): " 
                + quantile(19) + "</span><br>");
        document.write("<h3>Form copy scale: </h3>");
        // Changing th copy scale. 
        var copyscale = quantile.copy()
            .range([1.22, 11.5421, 2.2154, 3.2154]);
        document.write("<span>copyscale(2): " 
                + copyscale(2) + "</span><br>");
        document.write("<span>copyscale(19): " 
                + copyscale(19) + "</span><br>");
    </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
32445 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6813 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12028 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7198 POSTS0 COMMENTS
Thapelo Manthata
6893 POSTS0 COMMENTS
Umr Jansen
6881 POSTS0 COMMENTS