Saturday, September 6, 2025
HomeLanguagesJavascriptD3.js diverging.interpolator() Function

D3.js diverging.interpolator() Function

The diverging scales are very much similar to continuous scales. The only difference is that the output range of this scale is fixed by the interpolator thus the range is not configurable.

The diverging.interpolate() the function is used to configure the interpolator of the diverging scale. If the interpolator is not specified, it sets the interpolator of the scale to the specified function.

Syntax:

diverging.interpolator([interpolator]);

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

  • interpolator: This parameter accepts the interpolator function.

Return Values: This function does not return anything.

Below given are a few examples of the function given above.

Example 1:




<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport"
        path1tent="width=device-width, 
        initial-scale=1.0"/> 
    <title>GeekforGeeks</title>
    <script src="https://d3js.org/d3.v6.min.js"></script>
</head> 
<style>
</style>
<body> 
    <h2 style="color:green"> neveropen </h2>
    <h4> D3.js | diverging.interpolator() Function </h4>
    <script> 
        var diverging = d3.scaleDiverging()
        // Setting the interpolate function
                        .interpolator(d3.interpolateRainbow);
        // Default domain is used i.e [0, 1]
        document.write(
            "<p>diverging(0.1): ", diverging(0.1) + "</p>");
        document.write(
            "<p>diverging(0.2): ", diverging(0.2) + "</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"/> 
    <title>GeekforGeeks</title>
    <script src="https://d3js.org/d3.v6.min.js"></script>
</head> 
<style>
</style>
<body> 
    <h2 style="color:green"> neveropen </h2>
    <h4> D3.js | diverging.interpolator() Function </h4>
    <script> 
        var diverging = d3.scaleDiverging()
        // Setting the interpolate function
                        .interpolator(d3.interpolateSpectral)
        // Setting up the domain
                        .domain([1, 0.5, 10]);
        // Default domain is used i.e [0, 1]
        document.write(
            "<p>diverging(0.1): ", diverging(0.1) + "</p>");
        document.write(
            "<p>diverging(0.2): ", diverging(0.2) + "</p>");
    </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
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS