D3.js axis.tickSize() Function

The d3.axis.tickSize() function in D3.js is used to set the inner and outer tick size to the specified value and returns the axis. If size is not specified, returns the current inner tick size, which defaults to 6.

Syntax:

axis.tickSize([size])

Parameters: This function accepts single parameter as mentioned above and described below:

  • size: This parameter holds the size to set the inner and outer tick size.

Return Value: This function returns the axis.

Below programs illustrate the d3.axis.tickSize() function in D3.js:



Example 1:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    
<head
    <title
        D3.js | D3.axis.tickSize() Function 
    </title
    
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js"
    </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).tickSize(15); 
    
        var xAxisTranslate = height / 2; 
    
        svg.append("g") 
            .attr("transform", "translate(50, " 
                + xAxisTranslate + ")") 
            .call(x_axis)  
    </script
</body
</html>

chevron_right


Output:

Example 2:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    
<head
    <title
        D3.js | D3.axis.tickSize() Function 
    </title
    
    <script type="text/javascript" 
        src="https://d3js.org/d3.v4.min.js"
    </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 yscale = d3.scaleLinear() 
            .domain([0, 1]) 
            .range([height - 50, 0]); 
    
        var y_axis = d3.axisRight() 
            .scale(yscale).tickSize(0);
    
        svg.append("g") 
            .attr("transform", "translate(100,20)") 
            .call(y_axis)  
    </script
</body
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.