Skip to content
design
Components

Chart legend

Identify visible chart series with names, stable palette slots and matching mark patterns.

On this page
  • Primary
  • Comparison
Identify visible chart series with names, stable palette slots and matching mark patterns.
Code
import { ChartLegend } from "@bosunkit/components/chart-legend";
import type { ChartRegistry } from "@bosunkit/components/chart-container";
import type { ReactElement } from "react";

export const description: string =
  "A standalone key keeps each series' registry color and pattern when only a subset is visible.";
const config: ChartRegistry = {
  primary: { label: "Primary", formatValue: String, color: "02" },
  comparison: { label: "Comparison", formatValue: String, color: "09" },
};
export default function SeriesKey(): ReactElement {
  return <ChartLegend config={config} label="Comparison series" />;
}

The chart legend is a wrapping list of series names and swatches. It accepts the same complete registry as the drawing and an ordered subset of visible keys. It works outside the chart container, including in ChartPanel's legend slot.

01One series definitionNames, palette slots and patterns come from the same registry used by the drawing.
02Caller-formatted valuesThe caller supplies display text and quantity formatters; missing values have an explicit description.
03Accessible inspectionNames and patterns supplement color, and analytical plots expose their observations in a source table.

Use

The legend is descriptive. Selection belongs to the caller's controls. Filtering preserves each series' palette slot and pattern because appearance resolves against the complete registry. Line swatches show dash patterns; bar swatches show the drawing's fill pattern. The operational palette has nine slots; labels and patterns distinguish series when colors coincide or forced colors are active.

Use mark="point" with ScatterChart. Its circles, squares and triangles follow the complete registry’s solid, dashed and dotted patterns, so filtering preserves each series’ marker shape.

Examples

Series key

  • Primary
  • Comparison
A standalone key keeps each series' registry color and pattern when only a subset is visible.
Code
import { ChartLegend } from "@bosunkit/components/chart-legend";
import type { ChartRegistry } from "@bosunkit/components/chart-container";
import type { ReactElement } from "react";

export const description: string =
  "A standalone key keeps each series' registry color and pattern when only a subset is visible.";
const config: ChartRegistry = {
  primary: { label: "Primary", formatValue: String, color: "02" },
  comparison: { label: "Comparison", formatValue: String, color: "09" },
};
export default function SeriesKey(): ReactElement {
  return <ChartLegend config={config} label="Comparison series" />;
}

Keep series identity stable

Choose the series order deliberately and retain it across filters and refreshes. A hidden series does not cause another series to inherit its color or pattern. Place the legend close to the drawing, with complete names that remain understandable without color.

Use separate, labeled controls for visibility because this legend is descriptive. If a series represents a forecast or a derived value, explain that meaning in its label and surrounding panel. A legend does not replace axis units, the time reference or a source table for exact observations.

Props

PropTypeDefaultDescription
configrequiredChartRegistry–The same complete registry used by the drawing.
seriesreadonly string[] | undefinedObject.keys(config)The shown series in display order; all registry keys by default.
labelrequiredstring–The list's accessible name, translated by the caller.
mark"line" | "bar" | "point" | undefined"line"Draw line-pattern, patterned-bar or point-shape swatches; line by default.
classNamestring | undefined–Classes added to the list.
testIdstring | undefined–Becomes data-testid on the list.
refRef<HTMLUListElement> | undefined–The legend list.
Do
  • Primary
  • Comparison
Name the observations and keep the comparison basis visible.
Don't

Keep a gap and describe the missing measurement in the source table.

A missing observation must not appear to be zero.
  • Data visualization: scales, missing measurements and comparable evidence.
  • Chart panel: titles, controls and source information.
  • Sparkline: compact trends with operational integrity and forecast information.