D3.js | d3.continuous() Function

The d3.continuous() function in D3.js is used to return the corresponding value from the range if a value from the domain is given.

Syntax:

d3.scaleLinear().domain(array of values).range(array of values);

Parameters: This function does not accept any parameters.



Return Value: This function returns the corresponding range value for the domain’s value.

Below programs illustrate the d3.continuous() function in D3.js:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        D3.js | d3.continuous() Function
    </title>
      
    <script src = 
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
          
        // Calling the scaleLinear() function
        var A = d3.scaleLinear().domain([10, 50])
                .range([0, 100]);
          
        // Getting the corresponding range for
        // the domain value
        console.log(A('15'));
        console.log(A('20'));
        console.log(A('25'));
        console.log(A('30'));
    </script>
</body>
  
</html>

chevron_right


Output:

12.5
25
37.5
50

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        D3.js | d3.continuous() Function
    </title>
      
    <script src = 
        "https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
          
        // Calling the scaleLinear() function
        var A = d3.scaleLinear().domain([1, 5])
                .range([0, 10]);
           
        // Getting the corresponding range for
        // the domain value
        console.log(A('1'));
        console.log(A('2'));
        console.log(A('3'));
        console.log(A('4'));
    </script>
</body>
  
</html>

chevron_right


Output:

0
2.5
5
7.5

Reference: https://devdocs.io/d3~5/d3-scale#_continuous



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.