From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using colour scales

Using colour scales - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Using colour scales

- [Instructor] In D3, we often use color to express data. For example, a darker color might mean a higher value or red might mean one thing and green another. In cases where color is a range, it's appropriate to use a scale, since a scale just translates values from one range into values in another. We're just going to look quickly at some of the color ranges that D3 provides for us automatically. There are eight here: interpolate warm, interpolate cool, interpolate rainbow, that's the one we're going to be using shortly. You can see there's a few of them. Now actually, you can generate your own custom ranges as you see fit, but for now we're going to use interpolate rainbow because it's got the greatest number of quite bright colors. So what we're going to do, back in our shapes file, is color our rectangles using one of those color ranges. The first thing to do is to declare a new color scale. And we're going to say var rainbow equals d3.scaleSequential().domain(). Color scales…

Contents