Sequential scales are very similar to continuous scale. On a continuous scale, mapping is done in a continuous way between domain and range. The only difference is that the output range of this scale is fixed by its interpolator and this range cannot be changed.
The sequential.domain() function is used to set the domain of the given sequential scale. The domain array always accepts two numeric values.
Syntax:
sequential.domain([domain]);
Parameters: This function accepts a single parameter as mentioned above and described below:
- domain: This sets the minimum and maximum domain value for the scale.
Return Values: This function does not return any value.
Example 1:
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" /> < meta name = "viewport" path1tent=" width = device -width, initial-scale = 1 .0"/> < script src = </ script > </ head > < body > < h2 style = "color:green" > neveropen </ h2 > < h4 > D3.js | sequential.domain() Function </ h4 > < script > var sequential = d3.scaleSequential() // Setting domain to [10,20] .domain([10,20]); document.write("< h4 >From original scale:</ h4 >"); document.write("< p >sequential(11): ", sequential(11) + "</ p >"); document.write("< p >sequential(16): ", sequential(16) + "</ p >"); </ script > </ body > </ html > |
Output:
Example 2: When a domain is given as string numbers it is parsed to number.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" /> < meta name = "viewport" path1tent=" width = device -width, initial-scale = 1 .0"/> < script src = </ script > </ head > < body > < h2 style = "color:green" > neveropen </ h2 > < h4 > D3.js | sequential.domain() Function </ h4 > < script > var sequential = d3.scaleSequential() // Setting domain to ["10","100"] .domain(["10","100"]); document.write("< p >sequential(10): ", sequential(10) + "</ p >"); document.write("< p >sequential(100): ", sequential(100) + "</ p >"); </ script > </ body > </ html > |
Output: