D3.js continuous.tickFormat() Function

The continuous.tickFormat() function is used to change the format of the tick values. It returns a number format function that is suitable for displaying a tick value.
Syntax:
continuous.tickFormat( count, specifier )
Parameters: This function accepts two parameters as mentioned above and described below.
- count: It is the number of tick values to be used. It is an optional parameter.
- specifier: It is a string which specifies the format to be used. It is an optional parameter.
Return Values: This function does not return anything.
The program below illustrates the continuous.tickFormat() function in D3.js:
Example 1:
HTML
<!DOCTYPE html> <html> <head> </script> <script src= </script> <script src= </script> <script src= </script> </head> <body> <h1 style="color: green"> zambiatek </h1> <p>continuous.tickFormat() Function </p> <script> var x = d3.scaleLinear() .domain([0, 1]) .range([1, 2, 3, 4, 5, 6]); var ticks = x.ticks(3) var tickFormat = x.tickFormat(3, " %"); document.write("<h3>" + ticks.map(tickFormat) + "</h3>"); </script> </body> </html> |
Output:
Example 2:
HTML
<!DOCTYPE html> <html> <head> </script> <script src= </script> <script src= </script> <script src= </script> </head> <body> <h1 style="color: green"> zambiatek </h1> <p>continuous.tickFormat() Function </p> <script> var x = d3.scaleLinear() .domain([0, 1]) .range(["red", "blue", "green", "orange"]); var ticks = x.ticks(5) var tickFormat = x.tickFormat(5, " $"); 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!




