Open In App

D3.js scaleSequential() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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.

  • domain: This is the maximum and minimum input value range. The default domain is [0, 1].
  • interpolator: This takes an interpolator function. If it is not specified it defaults to the identity function.

Return Values: This function returns a function.

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">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:

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">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:



Last Updated : 31 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads