Scales

What's a scale?

D3 scales are functions that map from an input “domain” of data values to an output “range” of visual values (typically pixel positions, lengths, colors, etc.). They form a core part of D3’s data-driven approach, enabling you to translate raw data into on-screen representations in a declarative way. They're used extensively in nivo components.

You'll often encounter scale controls in the interactive documentation. But because scales heavily depend on the shape of the data, which is pre-defined in these docs, you might not be able to try-out all available scale types directly there.

Linear scale

A linear scale is the most basic quantitative (continuous) scale in D3. It defines a piecewise‐linear mapping from a numeric input domain to a numeric output range.

Linear scale use case

Linear scale configuration

The most minimal linear scale configuration is: scale={{ type: 'linear' }}

KeyTypeDefaultDescription
minnumber | 'auto'0

Minimum value, if auto, it's inferred from the data.

maxnumber | 'auto'auto

Maximum value, if auto, it's inferred from the data.

nicebooleantrue

Expands the values to “round” human-friendly values.

roundbooleanfalse

Round the output values to the nearest integer (e.g. x/y position).

reversebooleanfalse

Reverse the scale output range (e.g. x/y position).

clampbooleanfalse

For any input outside the domain, clamp the output to the nearest endpoint.

Linear scale interactive demo

Band scale

A band scale is an ordinal scale that maps a set of discrete input values (your categories) to a continuous numeric output range by dividing that range into uniform “bands”.

It’s perfect for bar charts or any time you need evenly-spaced slots for each category.

Band scale use case

Band scale configuration

The most minimal band scale configuration is: scale={{ type: 'band' }}

KeyTypeDefaultDescription
roundbooleanfalse

Round the output values to the nearest integer (e.g. x/y position).

Band scale interactive demo

Log scale

A log scale is a continuous quantitative scale that transforms strictly positive input values by applying a logarithmic function, so that equal ratios in the domain map to equal additive steps in the output range.

It’s ideal when your data spans multiple orders of magnitude and you want each constant factor (e.g. 1→10→100) to occupy the same visual interval, but it only handles values > 0 and cannot represent zeros or negatives.

Log scale use case

Log scale configuration

The most minimal log scale configuration is: scale={{ type: 'log' }}

KeyTypeDefaultDescription
minnumber | 'auto'auto

Minimum value, if auto, it's inferred from the data.

maxnumber | 'auto'auto

Maximum value, if auto, it's inferred from the data.

nicebooleantrue

Expands the values to “round” human-friendly values.

roundbooleanfalse

Round the output values to the nearest integer (e.g. x/y position).

reversebooleanfalse

Reverse the scale output range (e.g. x/y position).

Log scale interactive demo

Symlog scale

A symlog scale is a continuous quantitative scale that combines linear behavior around zero with logarithmic behavior farther out, on both the positive and negative sides.

It’s ideal when your data spans several orders of magnitude but also includes values near zero (including negatives) that you don’t want “crushed” by a pure log scale.

Symlog scale use case

Symlog scale configuration

The most minimal symlog scale configuration is: scale={{ type: 'symlog' }}

KeyTypeDefaultDescription
minnumber | 'auto'auto

Minimum value, if auto, it's inferred from the data.

maxnumber | 'auto'auto

Maximum value, if auto, it's inferred from the data.

nicebooleantrue

Expands the values to “round” human-friendly values.

roundbooleanfalse

Round the output values to the nearest integer (e.g. x/y position).

reversebooleanfalse

Reverse the scale output range (e.g. x/y position).

Symlog scale interactive demo