Skip to content
InsightCharts

Search

Search guides and components

Legend key

A standalone colour key: categorical swatches, or a sequential/diverging ramp with end labels.

Use when
When several charts (small multiples, a map and a bar chart, a dashboard row) share one colour encoding, show the key once above them and turn their own legends off.
Avoid when
A single chart: its built-in legend or, better, direct labels already do this. Do not list more than eight categories.

Preview

Source of electricity
  • Solar
  • Wind
  • Hydro
  • Gas
  • Other

Composition

Used in

1 molecule and 1 template use legend key.

Molecules

1

Repeats any chart spec once per value of a facet field, each panel with its own filtered rows and a title, in a grid that follows the container width.

Templates

1

A long article read by scrolling. It has a headline, then an ordered list of blocks in a reading column, then a source note. The blocks are prose, figures, charts with a callout, scrolly sequences, pull quotes, stat rows, small multiples and chapter breaks. Exhibits can be wider than the column.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/legend-key

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { LegendKey } from "insightcharts";

Examples

Sequential ramp

Share of electricity from renewables

Diverging, stepped

Change in house prices, 2019 to 2024

Lines, vertical, explicit order

  • Germany
  • Spain
  • EU average

Props

PropTypeDefaultDescription
scale"categorical" | "sequential" | "diverging"Defaults to categorical when items is given, otherwise sequential.
items(string | { label, color?, index?, shape?, muted? })[]Categorical entries. Colours come from the theme's categorical order by position (or index) unless given.
labelsstring[]Ramp end labels: [low, high] or [low, middle, high].
colorsstring[]Ramp colours, low to high. Defaults to the theme's sequential or diverging ramp.
steppedbooleanfalseDiscrete steps instead of a continuous gradient, for binned scales.
titlestringWhat the key encodes.
shape"square" | "line" | "dot""square"Default swatch shape: match the marks.
orientation"horizontal" | "vertical""horizontal"Categorical layout.
widthnumber240Ramp width in px, capped at the container.
align"left" | "center""left"Alignment within the container.