Skip to content
InsightCharts

Search

Search guides and components

Before and after

Two states of one measure side by side, as figures or small charts, with the change between them stated in the middle.

Use when
A single measure at two moments or under two conditions: before and after a policy, control and treatment, last year and this. The change is computed from the two values unless you state it.
Avoid when
More than two states (use line chart or slope chart); many entities each with a before and after (use dumbbell chart or arrow chart); two unrelated figures (use stat row).

Preview

Solar module prices fell from $0.74 to $0.15 per watt between 2013 and 2023

Average price of crystalline silicon modules, US dollars per watt

2013
Per watt
$0.74
2013 average
Down −79.7%
in ten years
2023
Per watt
$0.15
2023 average

Source: IRENA Renewable Power Generation Costs 2023 · Rounded, approximate figures for illustration

Composition

Built from

The pieces before and after renders or expects in its slots.

Atoms

4

Compares a value across categories with bars from a zero baseline.

A featured statistic with its label, change and the context that gives it meaning.

An inline change indicator: direction arrow, signed value and an optional baseline label.

A word-sized line or bar series without axes, with the latest point marked.

Used in

No template lists before and after in its composes. It still fits any slot that takes a component.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/before-after

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { BeforeAfter } from "insightcharts";

Examples

Two charts, change stated in words

The median midday price fell from €44 to €12 per MWh between summer 2019 and summer 2024

Median day-ahead price by hour, euros per MWh, same scale

Summer 2019
Down −€32
at midday
Summer 2024

Illustrative data

Figures with sparklines

Before the redesign
Monthly churn
4.2%
Down −50%
after six months
After
Monthly churn
2.1%

Props

PropTypeDefaultDescription
beforerequired{ heading?, value?, label?, context?, format?, chart? }The first state: a figure, a chart slot, or both.
afterrequired{ heading?, value?, label?, context?, format?, chart? }The second state.
deltanumber | stringThe change stated between the two. Default: the relative change when both values are numbers.
deltaLabelstringWords under the change, e.g. "in five years".
deltaFormatFormatSpecsigned percentNumber format for a numeric delta.
upIsGoodbooleantrueWhether an increase is good news; decides the colour of the change.
formatFormatSpec"auto"Number format shared by both values.
titlestringThe change stated plainly, with both values and the period.
subtitlestringMeasure and population.
sourcestringShown underneath as "Source: ...".
notestringMethod note or caveat.
themeThemeInputTheme override, passed on to both states.
mode"auto" | "system" | "light" | "dark""auto"Colour mode.