Band Scales

The band scale was introduced for helping us space out bars across an x-axis.

We are going to learn a new scale called a band scale. We will talk about it in a moment, but first, let’s create a scale for the y-axis. The y-axis will measure the population. We are going to use a linear scale for the y-axis.

Before getting started, remove the console statement for the stackData variable if you are working locally. We don’t need it anymore.

Linear scale

We will create a variable called yScale. Its value will be the d3.scaleLinear() function.

Press + to interact
const yScale = d3.scaleLinear()
.domain([
0, d3.max(stackData, ag => d3.max(ag, s => s[1]))
])
.rangeRound([dimensions.ctrHeight, dimensions.margins])

For the domain, the lower end of the range will be 0. As for the higher end ...

Access this course and 1400+ top-rated courses and projects.