Skip to content
GeneralGenerated from the public API

HistogramChart

Compare series and read the change behind them, with the axes, legend and tooltip already wired.

@luc/ui/charts

What it shows

Read the frequency distribution of a sample across explicitly supplied bins.

Live preview

A pre-binned sample of 149 observations; the chart counts nothing and bins nothing.

<HistogramChart
  bins={[
    { from: -3, to: -2, count: 4 },
    { from: -2, to: -1, count: 19 },
    { from: -1, to: 0, count: 47 },
    { from: 0, to: 1, count: 52 },
    { from: 1, to: 2, count: 21 },
    { from: 2, to: 3, count: 6 },
  ]}
  xFormat={{ kind: "percent", decimals: 0 }}
  format={{ kind: "integer" }}
  annotations={{ referenceLines: [{ value: 0, label: "Zero", axisLabel: true, tone: "neutral" }] }}
  height={320}
  ariaLabel="Distribution of returns"
/>

Controls

Height

320px

A chart measures its container, so it always needs a definite height.

State

The surface the chart is in — loading, empty and error are drawn by the component.

Accessible name

A drawing is not readable by a screen reader, so it needs a name that states what it shows.

The same fixture as the live preview above; the controls change how it is drawn, not what it measures.

Code
import { HistogramChart } from "@luc/ui/charts";

<HistogramChart
  bins={[
    { from: -3, to: -2, count: 4 },
    { from: -2, to: -1, count: 19 },
    { from: -1, to: 0, count: 47 },
    { from: 0, to: 1, count: 52 },
    { from: 1, to: 2, count: 21 },
    { from: 2, to: 3, count: 6 },
  ]}
  xFormat={{ kind: "percent", decimals: 0 }}
  format={{ kind: "integer" }}
  annotations={{ referenceLines: [{ value: 0, label: "Zero", axisLabel: true, tone: "neutral" }] }}
  height={320}
  ariaLabel="Distribution of returns"
  state="ready"
/>

Not controllable here

  • series / rows — The numbers are the caller's; the fixture above is the example.
Copy for an AI agentA specification an agent can act on: the import, the setup, the chosen props, the data contract and the accessibility expectation.
Implement `HistogramChart` from Luc UI. It is: Compare series and read the change behind them, with the axes, legend and tooltip already wired.

Import it with: import { HistogramChart } from "@luc/ui/charts";
Requires: react ^19.0.0; react-dom ^19.0.0; react-hook-form ^7.0.0 (optional, for @luc/ui/forms/react-hook-form); tailwindcss ^4.0.0; node >= 22 (repository tools). Import the stylesheet once at the app root and wrap the tree in `LucProvider`. Both come from the package that publishes @luc.

Chosen configuration: `height={320}`, `state="ready"`, `ariaLabel="Distribution of returns"`.

Accessibility: keep the component's own semantics. Do not re-implement its ARIA wiring, do not add roles it does not declare, and make sure every interactive element is reachable and operable from the keyboard with a visible focus state.
Styling: use Luc UI design tokens and the component's own props. Do not restyle with raw colour literals and do not override the component's internal structure with page CSS.
Motion: respect `prefers-reduced-motion`. The component already does, so do not disable it.

Reproduce this state:
```tsx
<HistogramChart
  bins={[
    { from: -3, to: -2, count: 4 },
    { from: -2, to: -1, count: 19 },
    { from: -1, to: 0, count: 47 },
    { from: 0, to: 1, count: 52 },
    { from: 1, to: 2, count: 21 },
    { from: 2, to: 3, count: 6 },
  ]}
  xFormat={{ kind: "percent", decimals: 0 }}
  format={{ kind: "integer" }}
  annotations={{ referenceLines: [{ value: 0, label: "Zero", axisLabel: true, tone: "neutral" }] }}
  height={320}
  ariaLabel="Distribution of returns"
  state="ready"
/>
```

Usage

The values are prepared by the caller: this component draws the points it is given and computes no statistic of its own, so units, scaling and any summary have to be settled before the data reaches it.

It is drawn by the ECharts engine.

Worked examples with real data are on the family overview: General

import { HistogramChart } from "@luc/ui/charts";
<HistogramChart
  bins={[
    { from: -3, to: -2, count: 4 },
    { from: -2, to: -1, count: 19 },
    { from: -1, to: 0, count: 47 },
    { from: 0, to: 1, count: 52 },
    { from: 1, to: 2, count: 21 },
    { from: 2, to: 3, count: 6 },
  ]}
  xFormat={{ kind: "percent", decimals: 0 }}
  format={{ kind: "integer" }}
  annotations={{ referenceLines: [{ value: 0, label: "Zero", axisLabel: true, tone: "neutral" }] }}
  height={320}
  ariaLabel="Distribution of returns"
/>

Data contract

`bins` contains `{ from, to, count }` rows. Bins are the caller's; the chart neither bins raw observations nor rescales counts.

Important configuration

Use `xFormat` for the measured unit, `format` for counts, and `annotations.referenceLines` for a meaningful zero, target or threshold.

Guidelines

When not to use

Do not pass raw observations and expect the chart to choose bins, and do not compare histograms with undisclosed bin widths.

Configuration

Exported symbols
ExportKindSignature
HistogramChart16 documented props({ bins, xFormat, format, tone, annotations, title, description, state, height, className, ariaLabel, ariaDescription, xLabel, yLabel, onReady, onEvent, }: HistogramChartProps) => import("@types/reac…

HistogramChart props

Type: HistogramChartProps

Values the compiler reads from the declaration.

HistogramChart props
PropTypeDefaultNotes
annotations?AnnotationSpec | undefined—
ariaDescription?string | undefined—
ariaLabel?string | undefined—
binsreadonly HistogramBin[]—Pre-binned data. Binning is the caller's job — see docs/CHART_GUIDE.md.
className?string | undefined—
description?string | undefined—
format?ChartFormat | undefined—Format for the count axis.
height?string | number | undefined—
onEvent?((event: EChartEvent) => void) | undefined—
onReady?((chart: EChartsInstance) => void) | undefined—
state?ChartState | undefined—
title?string | undefined—
tone?SeriesTone | undefined—
xFormat?ChartFormat | undefined—Format for the bin edges on the x axis.
xLabel?string | undefined—Display name of the value axis ("Return", "Observations"). An unlabelled pair of numbers leaves the reader to guess which axis is the bin and which is the count. The name is prese…
yLabel?string | undefined—

Accessibility

A chart is a picture of data, so it needs a name that states what it shows, and the numbers must exist as text somewhere on the page — in a table or a written summary — because a drawing is not readable by a screen reader and cannot be copied.

What happens on the server, and when hydration changes it.

Luc UI v1.0HistogramChartdark theme