Charts
Histogram
The distribution of one measure, counted into equal-width bins.
import '@reactloom/charts/styles.css';
import { Histogram } from '@reactloom/charts';Examples
Page load times
Use the arrow keys to move between data points, Home and End to jump to the first and last.
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.
Use the arrow keys to move between data points, Home and End to jump to the first and last.
| Category | Respondents |
|---|---|
| 19–26 | 6 |
| 26–34 | 7 |
| 34–41 | 4 |
| 41–48 | 4 |
| 48–56 | 2 |
| 56–63 | 2 |
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
| Prop | Type | Default |
|---|---|---|
valuesrequiredThe raw values. | number[] | — |
binsNumber of bins. | number | — |
countLabelTable header of the counts. | string | 'Count' |
titlerequiredNames the figure. | string | — |
descriptionThe takeaway; a factual summary is generated when omitted. | ReactNode | — |
tableThe data table alternative. | 'toggle' | 'visible' | 'none' | 'toggle' |
height · valueFormat · formatValue · messagesAs 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.
| Attribute | Values |
|---|---|
[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.
| Key | Action |
|---|---|
| Tab | Focus the plot |
| ← → ↑ ↓ | Move between items |
| Home / End | First / last item |
| Escape | Clear the highlight |
Usage guidelines
Do
- Say the unit in the title.
Don’t
- Don't compare categories with a histogram — use a BarChart.