Drawing the Axis
We'll look at a few special ways we can refine an axis's appearance by removing the outer ticks.
We'll cover the following...
We are going to draw an axis to help us read the data. The states should be drawn across the x-axis. The population should be drawn on the y-axis. If you would like, try adding an axis as an exercise. You already know how to accomplish this task. Try tackling this challenge before proceeding.
Solution
If you were able to draw the axes, then that is great. If not, that is fine, too. We will draw the axes together. We will be working at the bottom of the draw()
function.
The first step is to create the functions for drawing the axes. We will define a variable called xAxis
. It will be set to the d3.axisBottom
function.
// Draw Axisconst xAxis = d3.axisBottom(xScale)const yAxis = d3.axisLeft(yScale)
The axisBottom()
function will draw a horizontal axis with the ticks pointing downward. We need to pass in the xScale
function so that D3 understands how to draw the axis. Along with the x-axis, we are preparing the y-axis. We have a ...