The d3.scaleTime() function is used to create and return a new time scale which have the particular domain and range. In this function the clamping is disabled by default.
Syntax:
d3.scaleTime([[domain, ]range]);
Parameter: This function accepts two parameters as mentioned above and described below.
- Domain: It is an array of integers that defines the extent of domain values. If not specified then the default value is [2000-01-01, 2000-01-02].
- Range: It is an array of integers or string. If not specified then the default value is [0, 1].
Return Value: This function returns a function.
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 > Â Â Â Â </ script > Â Â Â Â < script src = Â Â Â Â </ script > Â Â Â Â < script src = Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â < h2 style = "color:green" >Geeks for neveropen</ h2 > Â Â Â Â < p >d3.scaleTime() Function</ p > Â Â Â Â < script > Â Â Â Â Â Â Â Â var time = d3.scaleTime() Â Â Â Â Â Â Â Â Â Â Â Â .domain([1, 10]) Â Â Â Â Â Â Â Â Â Â Â Â .range([10, 5]); Â Â Â Â Â Â Â Â document.write("< h3 >Type of d3.scaleTime() is: " Â Â Â Â Â Â Â Â Â Â Â Â + typeof (time) + "</ h3 >"); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â document.write("< h3 >time(10): "Â Â Â Â Â Â Â Â Â Â Â Â Â + time(10) + "</ h3 >"); Â Â Â Â </ script > </ body > Â Â </ html > |
Output:
Example 2:
HTML
<!DOCTYPE html> < html lang = "en" > Â Â < head > Â Â Â Â < meta charset = "UTF-8" /> Â Â Â Â < meta name = "viewport" path1tent = Â Â Â Â Â Â Â Â "width=device-width, initial-scale=1.0" /> Â Â Â Â </ script > Â Â Â Â </ script > Â Â Â Â < script src = Â Â Â Â </ script > Â Â Â Â < script src = Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â < h2 style = "color:green;" >Geeks for neveropen</ h2 > Â Â Â Â < p >d3.scaleTime() Function </ p > Â Â Â Â < script > Â Â Â Â Â Â Â Â var time = d3.scaleTime() Â Â Â Â Â Â Â Â Â Â Â Â .domain([1, 10]) Â Â Â Â Â Â Â Â Â Â Â Â .range([1, 100]) Â Â Â Â Â Â Â Â document.write("< h3 >time(1): " + time(1) + "</ h3 >") Â Â Â Â Â Â Â Â document.write("< h3 >time(2): " + time(2) + "</ h3 >") Â Â Â Â Â Â Â Â document.write("< h3 >time(3): " + time(3) + "</ h3 >") Â Â Â Â Â Â Â Â document.write("< h3 >time(4): " + time(4) + "</ h3 >") Â Â Â Â </ script > </ body > Â Â </ html > |
Output: