The time.tickFormat() function in D3.js is used to return a time format function suitable for displaying tick values. It returns the default time format when the specifier is not specified.
Syntax:
time.tickFormat( count, specifier )
Parameters: This function accepts two parameters as given above and described below:
- count: It specifies the number of tick values.
- specifier: It is the string that will be used as the specifier. It is of the format type “s”.
Return Values: This function does not return anything.
Below programs illustrate the time.tickFormat() function in D3.js:
Example 1:
HTML
<!DOCTYPE html> < html > < head > </ script > </ script > < script src = </ script > < script src = </ script > </ head > < body > < h1 style = "color: green" >neveropen</ h1 > < p >time.tickFormat() Function </ p > < script > var time = d3.scaleTime() // Specify the domain and range .domain([2001 - 01 - 01, 2005 - 01 - 02]) .range([1, 100]); var ticks = time.ticks(1); // Specify the format of the ticks var tickFormat = time.tickFormat(1, "%Y-%m-%d "); document.write("< h3 >" + ticks.map(tickFormat) + "</ h3 >"); </ script > </ body > </ html > |
Output:
Example 2:
HTML
<!DOCTYPE html> < html > < head > </ script > </ script > < script src = </ script > < script src = </ script > </ head > < body > < h1 style = "color: green" >neveropen</ h1 > < p >time.tickFormat() Function </ p > < script > var time = d3.scaleTime() // Specify the domain and range .domain([2001 - 01 - 01, 2005 - 01 - 02]) .range([1, 100]); var ticks = time.ticks(1); // Specify the format of the ticks var tickFormat = time.tickFormat(0, "%I %p"); document.write("< h3 >" + ticks.map(tickFormat) + "</ h3 >"); </ script > </ body > </ html > |
Output: