The pow.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:
pow.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 pow.tickFormat() function in D3.js:
Example 1:
html
<!DOCTYPE html> <html lang="en"> <head> Â Â <meta charset="UTF-8" /> Â Â <meta name="viewport"Â Â Â Â Â Â Â Â content="width=device-width, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â initial-scale=1.0" /> Â Â <title>neveropen</title> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> </head> <body> Â Â <h2 style="color: green">neveropen</h2> Â Â Â Â <p>pow.tickFormat() Function </p> Â Â Â Â <script> Â Â Â Â var x = d3.scalePow() Â Â Â Â Â Â .domain([0, 1]) Â Â Â Â Â Â .range([1, 2, 3, 4, 5, 6]) Â Â Â Â Â Â .exponent(0.5); Â Â Â Â Â Â var ticks = x.ticks(5) Â Â Â Â var tickFormat = x.tickFormat(100000, " %"); Â Â Â Â Â Â document.write("<h3>" +Â Â Â Â Â Â Â Â Â ticks.map(tickFormat) + "</h3>"); Â Â </script> </body> </html> |
Output:
Example 2:
html
<!DOCTYPE html> <html lang="en"> <head> Â Â <meta charset="UTF-8" /> Â Â <meta name="viewport"Â Â Â Â Â Â Â Â Â content="width=device-width, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â initial-scale=1.0" /> Â Â <title>neveropen</title> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> Â Â <script src= Â Â </script> </head> <body> Â Â <h2 style="color: green">neveropen</h2> Â Â Â Â <p>pow.tickFormat() Function </p> Â Â Â Â <script> Â Â Â Â var x = d3.scalePow() Â Â Â Â Â Â .domain([1, 10]) Â Â Â Â Â Â .range([10, 20, 30, 40, 50, 60]) Â Â Â Â Â Â .exponent(2); Â Â Â Â Â Â var ticks = x.ticks(5) Â Â Â Â var tickFormat = x.tickFormat(10, " $"); Â Â Â Â Â Â document.write("<h3>" +Â Â Â Â Â Â Â Â Â ticks.map(tickFormat) + "</h3>"); Â Â </script> </body> </html> |
Output:

