Open In App

D3.js sequential.interpolator() Function

Sequential scales are very similar to continuous scale. On 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.

The sequential.interpolator() function in d3.js is used to configure the interpolator of the scale. If the interpolator is specified it sets the interpolator of the scale to the specified function, else returns the scale’s current interpolator.



Syntax:

sequential.interpolator([interpolator]);

Parameters: This function accepts a single parameter as mentioned above and described below:



Return Values: This function does not return anything.

Example 1:




<!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.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4> D3.js | sequential.interpolator() Function</h4>
    <script>
        var sequential = d3.scaleSequential()
  
            // Setting the interpolator of the scale.
            .interpolator((t) => t * 2);
  
        document.write("<p>sequential(2): ", 
                    sequential(2) + "</p>");
  
        document.write("<p>sequential(4): ", 
                    sequential(4) + "</p>");
  
        document.write("<p>sequential(10): ", 
                    sequential(10) + "</p>");
  
        document.write("<p>sequential(20): ", 
                    sequential(20) + "</p>");
    </script>
</body>
  
</html>

Output:

Example 2:




<!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.v6.min.js">
    </script>
</head>
  
<body>
    <h2 style="color:green"> GeeksforGeeks </h2>
  
    <h4>D3.js | sequential.interpolator() Function</h4>
  
    <script>
        var sequential = d3.scaleSequential()
            // Setting the interpolator of the scale.
            .interpolator(d3.interpolateSpectral)
            // Setting the domain of the scale.
            .domain([1, 100]);
        document.write("<p>sequential(2): ", 
                    sequential(2) + "</p>");
  
        document.write("<p>sequential(4): ", 
                    sequential(4) + "</p>");
  
        document.write("<p>sequential(10): ", 
                    sequential(10) + "</p>");
  
        document.write("<p>sequential(20): ", 
                    sequential(20) + "</p>");
    </script>
</body>
  
</html>

Output:


Article Tags :