Skip to content
peakcharts

Histogram

How a set of raw numbers is spread out.

Session duration (minutes)
Session duration (minutes)Click a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.024689–16.1716.17–23.3323.33–30.530.5–37.6737.67–44.8344.83–529–16.17: 516.17–23.33: 723.33–30.5: 830.5–37.67: 537.67–44.83: 344.83–52: 3
Click a mark to pin its value
View data
Session duration (minutes)
LabelValue
9–16.175
16.17–23.337
23.33–30.58
30.5–37.675
37.67–44.833
44.83–523
<Histogram title="Session duration (minutes)" data={data} bins={6} />

Usage

Histogram.tsx
import { Histogram } from 'peakcharts';
import 'peakcharts/styles.css';

const data = [12, 18, 18, 24, 31, 33, 47, 9, 15, 22, 26, 28, 35, 41, 52, 14, 19, 23, 29, 30, 38, 44, 16, 21, 25, 27, 32, 36, 49, 21, 24];

export default function Example() {
  return <Histogram title="Session duration (minutes)" data={data} bins={6} />;
}

Data

data takes number[]. Input arrays are never mutated and order is preserved.

  • bins is an integer from 1 to 100 and defaults to 8.
  • The largest sample lands in the final bin. Identical samples use a padded domain.
  • The histogram helper returns the bins (lower, upper, label, value) if you want to draw your own.

Every chart also accepts the common props: description, height, color, variant, animate, formatValue and className.