Skip to content
peakcharts

Recipes

Short answers to the things people change first.

Format values

tsx
<LineChart
  title="Monthly revenue"
  data={data}
  formatValue={(v) => `$${(v / 1000).toFixed(1)}k`}
/>
Monthly revenue
Monthly revenueClick a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.08.4K16.8K25.2K33.6KJanFebMarAprMayJan: $21.4kFeb: $24.8kMar: $23.9kApr: $29.1kMay: $33.6k
Click a mark to pin its value
View data
Monthly revenue
LabelValue
Jan$21.4k
Feb$24.8k
Mar$23.9k
Apr$29.1k
May$33.6k

formatValue applies to axis labels, on-chart values, pinned captions and the data table.

Custom colors

tsx
<BarChart title="Revenue" data={data} color="#397766" />

<DonutChart
  title="Traffic sources"
  data={data}
  colors={['#087f8c', '#4f77c8', '#d28b41']}
/>

// or per datum
<PieChart title="Devices" data={[{ label: 'Desktop', value: 54, color: '#087f8c' }]} />
Traffic sources
Traffic sourcesClick a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.Organic: 46Direct: 31Referral: 23100Total
Click a mark to pin its value
Organic 46Direct 31Referral 23
View data
Traffic sources
LabelValue
Organic46
Direct31
Referral23

color sets the primary series. Pie, donut, funnel and treemap take colors, or a color on each datum.

Histograms

tsx
<Histogram title="Session duration" data={[12, 18, 18, 24, 31, 33, 47]} bins={6} />
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

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.

Waterfall

Values are signed changes to a running balance. Set total: true on a bar to treat it as an absolute balance measured from zero, such as an opening, subtotal or closing bar.

tsx
<WaterfallChart
  title="Revenue bridge"
  data={[
    { label: 'Opening', value: 240, total: true },
    { label: 'Sales', value: 160 },
    { label: 'Refunds', value: -48 },
    { label: 'Closing', value: 352, total: true },
  ]}
  negativeColor="#c2410c"
/>
Revenue bridge
Revenue bridgeClick a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.0106212318424OpeningSalesRefundsUpsellChurnClosingOpening: 240 (balance: 240)Sales: 160 (balance: 400)Refunds: -48 (balance: 352)Upsell: 72 (balance: 424)Churn: -35 (balance: 389)Closing: 389 (balance: 389)
Click a mark to pin its value
View data
Revenue bridge
LabelValueBalance
Opening240240
Sales160400
Refunds-48352
Upsell72424
Churn-35389
Closing389389

negativeColor overrides the decline color. The data table and pinned caption include running balances. The waterfall helper returns steps with start and end balances.

Heatmap

tsx
<HeatmapChart
  title="Activity"
  data={[
    { x: 'Mon', y: 'Morning', value: 12 },
    { x: 'Tue', y: 'Morning', value: 28 },
  ]}
/>
Activity
ActivityClick a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.MonTueWedThuFriMorningAfternoonEveningMorning, Mon: 12Morning, Tue: 28Morning, Wed: 34Morning, Thu: 19Morning, Fri: 8Afternoon, Mon: 22Afternoon, Tue: 41Afternoon, Wed: 47Afternoon, Thu: 38Afternoon, Fri: 25Evening, Mon: 9Evening, Tue: 14Evening, Wed: 21Evening, Thu: 17Evening, Fri: 30
Click a mark to pin its value
Low 8High 47
View data
Activity
Row / ColumnValue
Morning, Mon12
Morning, Tue28
Morning, Wed34
Morning, Thu19
Morning, Fri8
Afternoon, Mon22
Afternoon, Tue41
Afternoon, Wed47
Afternoon, Thu38
Afternoon, Fri25
Evening, Mon9
Evening, Tue14
Evening, Wed21
Evening, Thu17
Evening, Fri30

A missing pair renders blank, while an explicit 0 renders a low-intensity cell. Duplicate pairs and non-finite values are rejected.

Turn animation off

tsx
<AreaChart title="Visits" data={data} animate={false} />
Daily visits
Daily visitsClick a mark to pin its value; click it again to release. Keyboard: Enter or Space to pin, Escape to release. Data table below.0302.5605907.51.2KMonTueWedThuFriSatSunMon: 820Tue: 934Wed: 1,102Thu: 987Fri: 1,210Sat: 640Sun: 575
Click a mark to pin its value
View data
Daily visits
LabelValue
Mon820
Tue934
Wed1,102
Thu987
Fri1,210
Sat640
Sun575

Reduced-motion preferences always win, even when animate is true.

Dark mode

tsx
<div data-theme="dark">
  <BarChart title="Revenue" data={data} />
</div>

See Theming for toggling it from your own theme logic.