Friday, October 24, 2025
HomeLanguagesJavascriptD3.js interpolateNumber() Function

D3.js interpolateNumber() Function

The d3.interpolateNumber() Function is used to return the interpolator between two given numbers. It is almost the same as d3.interpolate() function except that it takes only numbers as parameters.

Syntax:

d3.interpolateNumber(a,b);

Parameters: This function accepts two parameters as mentioned above and described below.

  • a: It is any number on the number line.
  • b: It is any number on the number line.

Return Values: This function returns interpolator between two given numbers.

Below given are a few Examples of d3.interpolateNumber() function

Example 1:

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js d3.interpolateNumber() Function</title>
</head>
<style>
</style>
<body>
  <!--Fetching from CDN of D3.js -->
  <script type = "text/javascript" src = 
  </script>
  <script>
    let intr = d3.interpolateNumber(2458,9586)
    console.log("Type of returned function is: ",typeof(intr));
    console.log(intr(0.1))
    console.log(intr(1))
    console.log(intr(0.4))
  </script>
</body>
</html>


Output:

Example 2: When the number given is negative and one of them is not a number.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js d3.interpolateNumber() Function</title>
</head>
<style>
</style>
<body>
  <!--Fetching from CDN of D3.js -->
  <script type = "text/javascript" src = 
  </script>
  <script>
    console.log(d3.interpolateNumber(-263,586)(0.2))
    console.log(d3.interpolateNumber(-263,"green")(0.1))
    console.log(d3.interpolateNumber("yellow","red")(0.1))
  </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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS