From the course: D3.js Essential Training
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Creating a linear axis - D3.js Tutorial
From the course: D3.js Essential Training
Creating a linear axis
- [Instructor] Now it's really time to see D3 in action. We're going to start by adding an axis and then we'll break down how that works. So now that we've done the scale, adding the axis itself is very simple. You tend to add a group. You don't actually have to, you could add the axis directly to the SVG, but then your dom gets very messy. And I'm going to give that a class of axis and Y so we can tell what's what later. And then you simply say, call d3.axisRight and you provide the scale. Okay, save that and refresh. And can you see, we now have a very green line on the left hand side of our chart running from top to bottom. Now we can't see any tick labels probably because of that. Let's have a look. There we go. Okay, so we can see the axis. The labels are perhaps on the wrong side compared to what you might be expecting. And the axis currently is going from the top of the screen to the bottom, which makes for uncomfortable viewing. So generally you have a bit of a buffer or a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Introducing scales3m 40s
-
(Locked)
Position elements with a linear scale5m 51s
-
(Locked)
Creating a linear axis6m 8s
-
(Locked)
Positioning and formatting our axis7m 29s
-
(Locked)
Creating a time scale7m 33s
-
(Locked)
Creating a time series axis6m 10s
-
(Locked)
Creating an ordinal scale and axis11m 16s
-
(Locked)
Using color scales13m 36s
-
(Locked)
Challenge: Add Fahrenheit scale1m 18s
-
(Locked)
Solution: Add Fahrenheit scale3m 6s
-
(Locked)
-
-
-
-
-