Ordinal scales

Ordinal scales are the simplest; essentially just a dictionary, where keys are the domain and values are the range.

In the preceding example, we defined an ordinal scale by explicitly setting both the input domain and the output range. If we don't define a domain, it's inferred from use, but that can give unpredictable results.

A cool thing about ordinal scales is that having a range smaller than the domain makes the scale repeat values once used. Furthermore, we'd get the same result if the range was just ['red', 'yellow', 'green'].

Let's try a few out. We will create band and point scales, which are ordinal scales with extra pizazz. We also need to create a color scale that repeats itself. First, though, we need somewhere ...

Get D3.js 4.x Data Visualization - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.