In D3 version 4.x, d3.scale.ordinal()
has been changed to d3.scaleOrdinal
and d3.rangeRoundBands
has been changed to:
d3.scaleBand()
.rangeRound([range]);
To find the width of a band, what is the equivalent of d3.rangeBand()
?
In D3 version 4.x, d3.scale.ordinal()
has been changed to d3.scaleOrdinal
and d3.rangeRoundBands
has been changed to:
d3.scaleBand()
.rangeRound([range]);
To find the width of a band, what is the equivalent of d3.rangeBand()
?
To find the width of the band in a band scale you have to use:
According to the API,
bandwidth()
:Here is a demo:
As you can see, the bandwidth depends on the number of elements in the domain, the extent of the range and the paddings. Here is the same snippet above, with paddings: