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.continuous().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:
javascript
<!DOCTYPE html> <html> <head> <title> D3.js | d3.continuous() Function </title> <script src = </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> |
Output:
12.5 25 37.5 50
Example 2:
javascript
<!DOCTYPE html> <html> <head> <title> D3.js | d3.continuous() Function </title> <script src = </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> |
Output:
0 2.5 5 7.5
Reference: https://devdocs.io/d3~5/d3-scale#_continuous