DataDiff
DataDiff draws the added and removed counts per key as diverging bars on one shared symmetric scale.
- encodes
- diverging bar length per key — removed left, added right, one symmetric scale
- precision
- high
- nodes
- 2 per row + 2
DataDiff compares two versions of a dataset and gives each key a diverging bar: removed leftward, added rightward, both always drawn on one symmetric shared scale. Net is a mark you can turn on, never a replacement for the two bars. A table that added 500 rows and dropped 480 nets to +20, the same as one that added 20 and dropped nothing, and those are not the same event.
Install
import { DataDiff } from "@microcharts/react/data-diff";// diff — real values under “Sample data” below<DataDiff data={diff} title="Schema diff" />Sample data
// a schema migration diff — rows added/removed per tableconst diff = [ { key: "users", added: 340, removed: 120 }, { key: "orders", added: 88, removed: 30 }, { key: "items", added: 40, removed: 20 }, { key: "tags", added: 24, removed: 8 }, { key: "notes", added: 12, removed: 6 }, { key: "flags", added: 8, removed: 3 },];Try it
When to use it
Use it for a table cell per dataset version, a KPI card for a sync or import job, or any per-key added/removed audit where churn matters. For a plain ranking reach for MiniBar; for parts of a single whole, SegmentedBar.
Sizing
Variants
labels prints in-chart key tags, net adds a per-row tick at added − removed, and label="totals" prints a
+added / −removed footer. One symmetric scale spans every row, so a big change never shrinks to fit a small one; to
compare across charts, pass them a shared domain.
Edge cases
An empty data array renders an empty chart and reports "No data." A non-empty diff where every key is 0/0 still
draws a hairline placeholder tick per row and reports "No changes across 2 keys." A key with no change keeps its
row, so the absence of a change never reads as the absence of the key.
Four homes
Accessibility
The accessible name states the totals, the key count, and the single largest change: "+468 added, −170 removed across 3 keys; largest change: users (+220)." The interactive entry steps the rows and announces each key's added, removed, and net change.
The interactive entry follows the shared interaction contract:
arrow keys rove between units on both axes, Home and End jump to the ends, and a click, tap, Enter or
Space selects a unit — pinning its readout so it survives blur, until you select it again or press Escape.
On touch, a tap pins and a drag scrubs.
Props
| Prop | Type | Notes |
|---|---|---|
| data* | { key; added; removed }[] | Per-key change counts — added and removed are non-negative magnitudes. |
| labels | boolean | In-chart key tags for standalone use (host tables carry keys by default). |
| net | boolean | A tick at added−removed per row — a summary mark, never the two bars. |
| order | "data" | "net" | "magnitude" | Default 'data' keeps input order (schema order is often meaningful). |
| label | "totals" | "none" | 'totals' prints a +added / −removed footer. |
| maxItems | number | Row cap (default 12); rows beyond it are dropped with a dev warning. |
| animate | boolean | interactiveOpt-in entrance motion when the chart mounts client-side — add import "@microcharts/react/motion" once. Inert on the server, on hydrated server HTML, and under prefers-reduced-motion. |
Plus the shared grammar — data, domain, color, title, summary, format — and the layout props (width, height, className, style) that every chart accepts. Interactive entries also share animate and live, and — wherever a chart has more than one navigable unit — onActive, onSelect, selectedIndex and defaultSelectedIndex; and — wherever the chart shows a hover value — readout. See the shared grammar.