legend section controls where the legend sits and how it presents groups. A legend appears when a chart maps a visual aesthetic such as color or size. Under position: 'auto', a legend with a single item is dropped on bar, line, area and polar graphs.
Options
'auto' | 'top' | 'bottom' | 'left' | 'right' | 'none'
default:"auto"
Where the legend sits.
'none' hides it. 'auto' resolves to 'right' for a
line, area or unflipped stacked bar graph with three or more items, and to
'top' everywhere else, combo graphs included.'pill' | 'direct' | 'auto'
default:"auto"
How groups are labeled:
'pill'— a boxed legend with a swatch and label per group.'direct'— labels drawn next to each group’s endpoint, with no legend box. Reads well on line charts.'auto'—'direct'where the graph can anchor direct labels,'pill'otherwise.
position: 'stack' or 'fill'. Anywhere else 'direct' falls back to
'pill'.'auto' | 'start' | 'center' | 'end'
default:"auto"
Placement of the items along the legend’s flow:
- A horizontal (
top/bottom) legend runs along the row:startis left andendis right, on right-to-left pages too.centercenters on the panel, in line with the axis title. - A vertical (
left/right) legend runs down the column:startis top,endis bottom. 'auto'resolves tostartfor horizontal legends andcenterfor vertical ones.
Direct labels
Pin the legend to the right and ask for direct labels:style.directLabel paints them, not the legend targets.
Continuous color
Acolor scale that runs a ramp rather than a set of hues gets a legend of its own, one pill per domain stop: the low and high ends, plus the midpoint of a diverging ramp, each in the color the ramp gives that value. It never merges with another aesthetic’s legend and counts as one item for 'auto' placement. position, align and 'none' steer it like any other legend.
Headline numbers and the legend
A per-group headline names the same groups as a pill legend, so it takes the legend’s place. Direct labels stay.Hiding the legend
Related
- Mappings & aesthetics —
colorandgroupcreate groups - Scales — the color scale that assigns groups their swatches, and the ramps behind a color bar
- Layout —
style.legendmargin around a pill legend. Position stays onconfig.legend.

