The d3.axis.tickArguments() Function in D3.js is used to control which ticks are displayed by the axis. This function returns the axis generator
Syntax:
axis.tickArguments([arguments])
Parameters: This function accepts single parameter as mentioned above and described below:
- arguments: These parameters are used to display the number of ticks and to customize how the tick values are formatted.
Return Value: This function returns the axis generator.
Note: This is similar to d3.axis.tick() function but in this function, all arguments can be optional.
Below programs illustrate the d3.axis.tickArguments() function in D3.js:
Example 1:
HTML
<!DOCTYPE html> <html>   <head>     <title>         D3.js | D3.axis.tickArguments() Function     </title>       <script type="text/javascript"     </script>       <style>         svg text {             fill: green;             font: 15px sans-serif;             text-anchor: center;         }     </style> </head>   <body>     <script>         var width = 400, height = 400;         var svg = d3.select("body")             .append("svg")             .attr("width", width)             .attr("height", height);           var xscale = d3.scaleLinear()             .domain([0, 10])             .range([0, width - 60]);           var x_axis = d3.axisBottom()             .scale(xscale).tickArguments([5]);           var xAxisTranslate = height / 2;           svg.append("g")             .attr("transform", "translate(50, "                 + xAxisTranslate + ")")             .call(x_axis)     </script> </body>   </html> |
Output:
Example 2:
HTML
<!DOCTYPE html> <html>   <head>     <title>         D3.js | d3.axis.tickArguments() Function     </title>       <script type="text/javascript"     </script>       <style>         svg text {             fill: green;             font: 15px sans-serif;             text-anchor: end;         }     </style> </head>   <body>     <script>         var width = 400, height = 400;         var svg = d3.select("body")             .append("svg")             .attr("width", width)             .attr("height", height);           var yscale = d3.scaleLinear()             .domain([0, 1])             .range([height - 50, 0]);           var y_axis = d3.axisLeft()             .scale(yscale).tickArguments([3, "$.2f"]);           svg.append("g")             .attr("transform", "translate(100,20)")             .call(y_axis)     </script> </body>   </html> |
Output:

