An example of filtering ticks on an ordinal axis.
forked from mbostock's block: Ordinal Tick Filtering
xxxxxxxxxx
<meta charset="utf-8">
<style>
.body {
shape-rendering: crispEdges;
}
.grid-background {
fill: #FF0000;
}
.axis text {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 100, right: 100, bottom: 100, left: 100},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var border=1.5;
var bordercolor='black';
var x = d3.scale.ordinal()
.domain([1,2,3,4,5,6,7,8,9,10,11,12,13,14])
.rangeBands([0, 760]);
x.rangeBand(); // 33.333333333333336
x.range(); // [0, 33.333333333333336, 66.66666666666667]
x.rangeExtent(); // [0, 100]
var xAxis = d3.svg.axis()
.scale(x)
.tickValues(x.domain().filter(function(d, i) { return !(i % 1); }))
.orient("bottom");
var xAxisMinor = d3.svg.axis()
.scale(x)
.tickValues(x.domain().filter(function(d, i) { return !(i % 2); }))
.orient("top");
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("rect")
.attr("class", "grid-background")
.attr("width", width)
.attr("height", 20)
.style("stroke", bordercolor)
.style("fill", "none")
.style("stroke-width", border);;
svg.append("g")
.attr("class", "x axis")
.call(xAxis);
https://jsbin.com/rexosonoha/edit?html,css,js,output
</script>
https://d3js.org/d3.v3.min.js