Open In App

D3.js continuous.interpolate() Function

Last Updated : 23 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The continuous.interpolate() function is used to set the range interpolator factory which is used to create the interpolators for each pair of values from the range that are adjacent to each other.

Syntax:

continuous.interpolate( interpolate )

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

  • interpolator: This parameter accepts an interpolator.

Return Values: This function does not return anything.

The program below illustrates the continuous.interpolate() function in D3.js:

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0"/>
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
    <script src="https://d3js.org/d3-color.v1.min.js">
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color: green;">Geeksforgeeks</h2>
  
    <p>continuous.interpolateRound() Function </p>
  
    <script>
        var continuous = d3.scaleLinear()
            // Domain ranges -10, 0, 10
            .domain([-10, 0, 10])
            // Range for the domain
            .range([10, 20, 30, 40, 50, 60, 70, 80, 90])
            // Using interpolateRound
            .interpolate(d3.interpolateRound);
  
        document.write("<div>");
        document.write("<h3>" + continuous(1) + "</h3>");
        document.write("<h3>" + continuous(2) + "</h3>");
        document.write("<h3>" + continuous(3.5) + "</h3>");
        document.write("<h3>" + continuous(4.5) + "</h3>");
        document.write("<h3>" + continuous(5.5) + "</h3>");
        document.write("<h3>" 
            + continuous(-2.5) + "</h3></div>");
    </script>
</body>
  
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads