D3.js time.tickFormat() Function

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">zambiatek</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">zambiatek</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:
Whether youāre preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions weāve already empowered, and weāre here to do the same for you. Donāt miss out ā check it out now!




