Skip to main content
A scale turns data values into visual values — a number into a pixel position, a category into a color, a magnitude into a point size. Every aesthetic you map needs a scale to interpret it.

Position scales must be declared

Position scales are never created automatically. If you map x or y, you must add scale.x() / scale.y(). Miss one and that axis has no scale, producing NaN positions and a blank chart.
Visual scales (color, size, …) are more forgiving — a mapped color without an explicit scale falls back to the default palette — but declaring them keeps a chart predictable.

Inference vs explicit types

Position scales are callable to infer their type from the mapped column’s value format:
  • text → discrete (band) scale
  • number / percentage / currency → continuous scale
  • date → temporal scale
Or name the type explicitly when you want to force a treatment:

Scales by aesthetic

Color scales

Identity scales

An identity scale passes data values straight through as visual values — { size: 10 } becomes 10px, no transformation. Useful when your data already holds pixel sizes or CSS colors.

Continuous scale options

The continuous methods (and .log() / .sqrt(), which are continuous with a transform) accept:
domainMin
number | null
Force the lower bound of the domain. domainMin: 0 makes an axis start at zero.
domainMax
number | null
Force the upper bound of the domain.
nice
boolean
Extend the domain to round values — [3, 97] becomes [0, 100].
zero
boolean
Include zero in the domain.
reverse
boolean
Reverse the direction of the scale.
transform
'linear' | 'log' | 'sqrt'
A mathematical transform applied to the scale. scale.y.log() is shorthand for transform: 'log'.

Discrete scale options

domain
string[]
The categories, in the order they should appear. Omit to derive them from the data.
range
Array<string | number>
Explicit output values — colors, sizes, or dash patterns — aligned to domain.

Next