Open In App

D3.js scaleSequential() 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 d3.scaleSequential() function is used to create and return the sequential scale. This scale has a specified domain and fixed range.



Syntax:

d3.scaleSequential([[domain, ]interpolator]);

Parameters: The above-given function accept two parameters as mentioned above and described below.



Return Values: This function returns a function.

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.v4.min.js">
    </script>
</head
  
<body
    <h2 style="color:green">GeeksforGeeks</h2>
  
    <h4>d3.scaleSequential() Function</h4>
  
    <script
        var sequential= d3.scaleSequential(
            function(t) {
                return d3.rgb(t * 400, 1.5, 0.8);
            }
        )
  
        document.write("<p>sequential(0.1): ",
                sequential(0.1) + "</p>");
  
        document.write("<p>sequential(0.2): ",
                sequential(0.2) + "</p>");
          
        document.write("<p>sequential(0.3): ",
                sequential(0.3) + "</p>");
          
        document.write("<p>sequential(0.4): ",
                sequential(0.4) + "</p>");
          
        document.write("<p>sequential(0.5): ",
                sequential(0.5) + "</p>");
          
        document.write("<p>sequential(0.6): ",
                sequential(0.6) + "</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.v4.min.js">
    </script>
</head
  
<body
    <h2 style="color:green">GeeksforGeeks</h2>
  
    <h4>d3.scaleSequential() Function</h4>
  
    <script
        var sequential= d3.scaleSequential(
            function(t) {
                return d3.interpolateNumber(t * 400, 0, 10);
            }
        )
  
        document.write("<p>sequential(0.1)(-1): ",
                    sequential(0.1)(-1) + "</p>");
  
        document.write("<p>sequential(0.1)(1): ",
                    sequential(0.1)(1) + "</p>");
  
        document.write("<p>sequential(0.1)(0): ",
                    sequential(0.1)(0) + "</p>");
  
        document.write("<p>sequential(0.1)(0.5): ",
                    sequential(0.1)(0.5) + "</p>");
    </script
</body>
  
</html>

Output:


Article Tags :