Examples

Page load times

Preview
Page load time (ms)Histogram of 120 values from 161 to 849 in 8 bins. Most values fall in 677–763 (19).
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Example.tsx
import { Histogram } from '@reactloom/charts';

const loadTimes = Array.from({ length: 120 }, (_, i) => Math.round(420 + 260 * Math.sin(i * 1.7) + ((i * 37) % 180)));

export default function Example() {
  return <Histogram title="Page load time (ms)" values={loadTimes} bins={8} valueFormat={{ maximumFractionDigits: 0 }} />;
}

Automatic bins

Without bins, Sturges\u2019 rule picks the count.

Preview
Survey respondents by ageHistogram of 25 values from 19 to 63 in 6 bins. Most values fall in 26–34 (7).
Use the arrow keys to move between data points, Home and End to jump to the first and last.
Survey respondents by age (data)
CategoryRespondents
19–266
26–347
34–414
41–484
48–562
56–632
Example.tsx
import { Histogram } from '@reactloom/charts';

const ages = [19, 22, 23, 24, 25, 25, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 38, 41, 42, 44, 47, 51, 55, 58, 63];

// Without `bins`, the count follows Sturges' rule.
export default function Example() {
  return <Histogram title="Survey respondents by age" values={ages} countLabel="Respondents" valueFormat={{ maximumFractionDigits: 0 }} table="visible" />;
}

API reference

Histogram props
PropTypeDefault
valuesrequired
The raw values.
number[]—
bins
Number of bins.
number—
countLabel
Table header of the counts.
string'Count'
titlerequired
Names the figure.
string—
description
The takeaway; a factual summary is generated when omitted.
ReactNode—
table
The data table alternative.
'toggle' | 'visible' | 'none''toggle'
height · valueFormat · formatValue · messages
As on the other charts.
—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-active]present when on

Theme tokens it reads

--pl-color-border-default --pl-color-fg-default --pl-color-fg-muted

Accessibility

  • The chart is a figure named by its title and described by a summary; the drawing is hidden from assistive technology.
  • The plot is one tab stop: arrow keys move between items and each is announced; the data table gives every value.
Keyboard interactions
KeyAction
TabFocus the plot
← → ↑ ↓Move between items
Home / EndFirst / last item
EscapeClear the highlight

Usage guidelines

Do

  • Say the unit in the title.

Don’t

  • Don't compare categories with a histogram — use a BarChart.