023 / RECHARTS / BAR & COLUMN
Diverging Bars
Signed categorical bars extending above/below or left/right from a neutral reference, with symmetric scaling, direction-aware geometry, and factual deviation semantics.
- SPEC
- #023
- ENGINE
- Recharts
- FAMILY
- Bar & Column
- RENDERER
- svg
- STATUS
- preview
Installation
Checking public registry…
View local registry JSONCopied as source into your project (requires recharts).
Overview
Diverging Bars is Plotcn's canonical signed categorical visualization component designed specifically for comparing categorical deviations around an explicit neutral reference. It answers the fundamental analytical question:
“How does each categorical value deviate above or below a meaningful neutral reference?”
Secondary analytical questions answered by this component include:
- “What is the direction of the deviation (above, on, or below the reference)?”
- “How large is that deviation from the baseline?”
- “Which categories are above, below, or exactly on the reference?”
- “What was the original raw consumer observation before deviation was computed?”
import { DivergingBars } from "@/components/charts/recharts/bar-diverging"const regionalVariance = [ { region: "North", variance: 18 }, { region: "South", variance: -12 }, { region: "East", variance: 31 }, { region: "West", variance: -24 }, { region: "Central", variance: 0 },]export function RegionalVarianceChart() { return ( <DivergingBars data={regionalVariance} categoryKey="region" series={{ key: "variance", label: "Variance from Plan", valueFormatter: (v) => `${v}%`, }} baseline={0} showGrid /> )}Governing Principle
Diverging Bars encodes signed deviation around an explicit neutral reference. Position relative to the baseline communicates direction; bar length communicates magnitude of deviation. Neither direction is automatically positive or negative in the moral or evaluative sense.
This principle governs:
- API design and caller data immutability;
- derivation of deviation in mathematical comparison space;
- symmetrical quantitative domain resolution;
- direction-aware outward corner rounding;
- factual, non-judgmental tooltip language and accessibility narration;
- keyboard traversal and container-aware responsive layout.
Bar-Family Positioning
The Plotcn Bar family provides six distinct analytical specializations:
| Component | Registry ID | Primary Analytical Question | Quantitative Scale |
|---|---|---|---|
| Signal Bars (019) | bar-signal | "How do discrete categories compare on single or grouped measures?" | Grounded Zero () |
| Rank Bars (020) | bar-rank | "Which categories perform highest or lowest in top-N rank?" | Grounded Zero () |
| Group Compare (021) | bar-group-compare | "How do peer measures compare directly against each other?" | Shared Grounded Zero () |
| Stack Ledger (022) | bar-stack-ledger | "How do additive contributors compose the total magnitude?" | Additive Total () |
| Percent Stack (023) | bar-percent-stack | "How does the internal percentage composition differ across categories?" | Fixed Normalized () |
| Diverging Bars (024) | bar-diverging | "How does each value deviate above or below a neutral reference?" | Symmetric Deviation () |
Do not turn Diverging Bars into a generic mode of Signal Bars. Its baseline math, domain symmetry, color semantics, and directional labeling justify a dedicated component.
Diverging Model
The Diverging Bar Model: Direction by Side, Magnitude by Length
Analytical model of Diverging Bars showing values compared to an explicit baseline where position relative to the reference encodes direction (above, on, below) and bar length encodes deviation magnitude.
In the Diverging Bars analytical model:
- Baseline Spine: Represents the neutral reference (defaults to
0, but supports any finite numeric value). - Position Relative to Reference: Values above the reference extend outward to the positive side (right in horizontal layout, up in vertical layout). Values below extend to the negative side (left in horizontal layout, down in vertical layout).
- Bar Length: Strictly encodes the magnitude of the derived deviation
|value - baseline|. - Zero Deviation: Sits exactly on the reference baseline with a neutral marker and zero bar length.
Reference Baseline
Canonical Zero Baseline: Natural Positive and Negative Divergence
Visualization of a zero baseline where values diverge around zero with symmetrical quantitative axis extents.
Canonical Zero Baseline
When baseline = 0, the component operates in classical zero-centered signed mode:
value > 0→ Above reference (+ deviation)value = 0→ On reference (0 deviation)value < 0→ Below reference (− deviation)
Explicit Non-Zero Benchmark or Target
Diverging Bars truthfully supports non-zero baselines such as service targets, SLA budgets, quarterly goals, or industry averages:
Non-Zero Reference Baseline: Centering Geometry in Deviation Space
Diagram showing an API latency dataset with target SLA of 250ms where deviations are centered around 0 in rendered geometry.
<DivergingBars data={serviceLatencies} categoryKey="service" series={{ key: "latency", label: "API Latency", valueFormatter: (v) => `${v} ms`, }} baseline={250} baselineLabel="Target"/>For a raw observation of 310 ms against a baseline of 250 ms, the derived deviation is +60 ms. The bar geometry encodes the 60-unit deviation from the target, not 310 units from zero.
Negative Reference Baseline
A negative baseline reference is mathematically valid and fully supported:
Negative Baseline Reference: -80 is Above -100 Reference Baseline
Demonstration showing how values are compared with a negative baseline (-100), where -80 produces a positive deviation (+20) and sits above the reference line.
For baseline = -100 and rawValue = -80, the derived deviation is +20 (-80 - (-100) = +20). The observation sits above the reference line even though the raw value is negative.
Raw Value vs Deviation
Raw Consumer Value vs Derived Deviation: deviation = value - baseline
Step-by-step diagram illustrating how input raw values are preserved untouched while deviation is derived by subtracting the baseline, showing that raw sign does not dictate direction.
Plotcn strictly preserves consumer raw values canonical. Caller data records are never mutated.
- The consumer supplies raw observations (
value). - Plotcn derives
deviation = value - baseline. - Recharts renders bars inside zero-centered deviation space.
- Tooltips and accessibility layers present both raw values, reference baseline, and derived deviation.
Symmetric Domain
Symmetric Domain: Why Equal Geometric Lengths Must Represent Equal Magnitudes
Visual comparison between an asymmetric domain and Plotcn symmetric domain, showing how asymmetric extents distort perception of magnitude across the baseline.
A diverging chart benefits from equal visual distance on opposite sides of the neutral baseline.
- Default Symmetry:
[-maxAbsDeviation, +maxAbsDeviation] - Under this model, equal geometric bar lengths on opposite sides represent equal deviation magnitudes.
- If deviations range from
-20to+80, Plotcn scales the axis from-80to+80(or symmetrically niced bounds like[-100, +100]), preventing the misleading illusion that a small negative value is comparable to a large positive value. - All-Above & All-Below Datasets: Symmetrical domaining preserves the neutral baseline spine and opposing space, preventing the chart from silently collapsing into an ordinary one-sided bar chart.
Direction Semantics
Above Reference, Below Reference, and On Reference States
Three semantic cards explaining above reference, on reference, and below reference states and their visual representation.
deviation > 0
Observation strictly exceeds the baseline. Bar extends outward into positive/right region with outer rounded cap.
deviation = 0
Observation exactly matches reference. Rendered as a neutral baseline tick mark without artificial bar length.
deviation < 0
Observation falls below the baseline. Bar extends outward into negative/left region with outer rounded cap.
Plotcn uses factual, non-judgmental directional language:
Above reference(deviation > 0)On reference(deviation = 0)Below reference(deviation < 0)
Direction Is Not Judgment
Direction Is Position, Not Moral Judgment
Callout showing that above reference is not automatically good and below is not automatically bad, warning against default red/green coloring.
Never confuse:
positive numberorabove baselinewith agood outcome;negative numberorbelow baselinewith abad outcome.
For API latency, lower is better. For operational variance, zero deviation is ideal. Plotcn maintains semantic neutrality and avoids red/green moral judgment.
Installation
Checking public registry…
View local registry JSONCopied as source into your project (requires recharts).
Missing vs On Reference
Missing Value vs On Reference: Never Conflate Unavailable Data with Zero
Side-by-side comparison showing that known zero deviation sits on the baseline with a tick mark, whereas missing or null data renders no bar and states unavailable in tooltips.
- • rawValue: 100
- • baseline: 100
- • deviation: 0
- • position: "equal"
A real, finite metric was measured and exactly equals the baseline. Rendered with neutral tick mark.
- • rawValue: null / undefined
- • baseline: 100
- • deviation: null
- • position: "unavailable"
No observation recorded. Plotcn never substitutes 0. Category remains keyboard inspectable, displaying "Unavailable".
Plotcn maintains a strict distinction between known zero deviation and missing observations:
- On Reference (
deviation = 0): A valid numeric observation was measured and exactly equals the baseline. Rendered with a neutral baseline tick. - Missing (
null/undefined): No numeric observation was recorded. Plotcn never substitutes zero. No bar is drawn, and tooltips report"Unavailable".
Orientation & Layout
Orientation Layouts: Horizontal Left/Right vs Vertical Above/Below
Side-by-side diagrams of horizontal diverging layout (bars extending left and right from vertical baseline) versus vertical layout (bars rising and falling from horizontal baseline).
Diverging Bars supports both horizontal and vertical orientations:
- Horizontal (
layout="horizontal", default): Categories on vertical Y-axis, bars extend left/right from central vertical baseline spine. Optimal for signed categorical comparison and long category labels. - Vertical (
layout="vertical"): Categories on horizontal X-axis, bars extend up/down from horizontal baseline.
Category Hit Regions
Category Band Hit Testing: Forgiving Interaction for Zero and Tiny Bars
Illustration showing that the interaction surface spans the full category band height and width, enabling easy targeting of tiny or zero-magnitude values on mobile and touch devices.
To ensure accessibility and touch safety:
- Hit testing uses the full category band rather than only the visible bar rectangle.
- Zero-deviation and tiny-deviation bars remain easily inspectable on mobile devices without artificial visible inflation.
Animation & Baseline Crossing
Baseline Crossing Animation: Contraction and Expansion Without Teleportation
Step-by-step animation lifecycle showing a bar transitioning from positive (+20) to negative (-10) by contracting toward the baseline and expanding into negative space.
- Bars originate at the neutral baseline and grow outward.
- Data updates transitioning across the baseline contract toward zero before expanding into the opposing direction, preventing teleportation or overshoot.
- Fully honors
prefers-reduced-motion.
Rendering Architecture
DivergingBars Rendering Pipeline: From Raw Observations to Directional SVG
System architecture diagram detailing consumer records input, validation of finite baseline, deviation derivation, classification, symmetric domain calculation, and Recharts SVG rendering.
Data Contract
interface DivergingDatum { region: string variance: number | null}- Categories preserve caller order strictly without dynamic sorting or ranking.
- Raw values must be finite numbers;
NaNandInfinityare rejected as unavailable. - Baseline must be a finite number.
Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly TData[] | [] | Categorical data observations. Order preserved strictly. |
categoryKey | keyof TData & string | — | Property key identifying discrete categories. |
series | DivergingBarSeries<TData> | — | Semantic quantitative series { key, label, valueFormatter }. |
layout | "horizontal" | "vertical" | "horizontal" | Visual orientation layout. |
baseline | number | 0 | Explicit neutral reference baseline. |
baselineLabel | string | — | Optional semantic label (e.g. "Target", "SLA"). |
domain | [number, number] | "symmetric" | "symmetric" | Quantitative scale domain in deviation space. |
aboveColor | string | "var(--chart-1)" | Fill color for bars above the reference baseline. |
belowColor | string | "var(--chart-2)" | Fill color for bars below the reference baseline. |
baselineColor | string | "var(--chart-axis)" | Stroke color for reference baseline line. |
selectionColor | string | "var(--chart-selection)" | Stroke emphasis for active/selected bar. |
height | number | string | 340 | Chart container height in pixels. |
showGrid | boolean | true | Whether to render background grid lines. |
showLegend | boolean | false | Whether to render directional legend. |
valueLabel | "none" | "value" | "deviation" | "auto" | "none" | Inline numeric label rendering mode. |
maxBarSize | number | 36 | Maximum bar thickness in pixels. |
motion | boolean | { duration?: number } | true | Animation toggle honoring reduced-motion preferences. |
Accessibility
- Screen readers receive a descriptive analytical summary detailing categories above, below, and on reference.
- Offscreen HTML table includes Category, Raw Value, Reference Baseline, Deviation, and Position columns.
- Single chart tab stop with keyboard navigation:
- Horizontal:
ArrowUp/ArrowDown - Vertical:
ArrowLeft/ArrowRight Home/Endto jump to first / last category.
- Horizontal:
Props Reference & Interactive Prop Explorer
Inspect every component property, customize semantic color roles live with instant visual feedback, and copy production-ready code with active prop configurations.
Colors & Appearance Configuration
Customize primary, reference, or annotation series colors. Defaults derive from Plotcn theme tokens.
<DivergingBars
data={data}
categoryKey="region"
series={{ key: "variance", label: "Variance from Plan" }}
baseline={0}
/>Explicit neutral reference baseline against which deviation is derived (value - baseline).
baseline={0}Default: 0Visual layout: 'horizontal' (categories on Y) or 'vertical' (categories on X).
layout="horizontal"Default: "horizontal"Quantitative scale domain in deviation space. 'symmetric' scales [-maxAbs, +maxAbs].
domain="symmetric"Default: "symmetric"Whether to render subtle background gridlines.
showGrid={true}Default: trueWhether to display the directional legend.
showLegend={false}Default: falsePolicy for rendering inline numeric labels at outward bar ends.
valueLabel="none"Default: "none"| Property | Type | Default | Required | Description |
|---|---|---|---|---|
dataReq | readonly TData[] | [] | Yes | Array of categorical data records. Order is strictly preserved. |
categoryKeyReq | keyof TData & string | — | Yes | Key on data records representing the discrete category. |
seriesReq | DivergingBarSeries<TData> | — | Yes | Quantitative series definition containing key, label, and optional valueFormatter. |
baselineOpt | number | 0 | No | Explicit neutral reference baseline against which deviation is derived (value - baseline). |
string | undefined | No | Optional label for the baseline (e.g. 'Target', 'Plan', 'SLA'). | |
layoutOpt | "horizontal" | "vertical" | "horizontal" | No | Visual layout: 'horizontal' (categories on Y) or 'vertical' (categories on X). |
domainOpt | [number, number] | "symmetric" | "symmetric" | No | Quantitative scale domain in deviation space. 'symmetric' scales [-maxAbs, +maxAbs]. |
aboveColorOpt | string | "var(--chart-1)" | No | Fill color for bars deviating above the neutral baseline reference. |
belowColorOpt | string | "var(--chart-2)" | No | Fill color for bars deviating below the neutral baseline reference. |
string | "var(--chart-axis)" | No | Stroke color for the structural baseline reference line. | |
string | "var(--chart-selection)" | No | Accent stroke color for the currently inspected category bar. | |
showGridOpt | boolean | true | No | Whether to render subtle background gridlines. |
showLegendOpt | boolean | false | No | Whether to display the directional legend. |
valueLabelOpt | "none" | "value" | "deviation" | "auto" | "none" | No | Policy for rendering inline numeric labels at outward bar ends. |
heightOpt | number | string | 340 | No | Container height in pixels or CSS dimension string. |
maxBarSizeOpt | number | 36 | No | Maximum bar thickness in pixels. |
motionOpt | boolean | { duration?: number } | true | No | Animation toggle honoring reduced-motion preferences. |
Component Variants & Edge States
Production cookbooks showcasing configuration variants alongside verified handling of loading, empty data, and network error states.
Variance from Plan (Zero Baseline)
Regional performance variance around a zero neutral reference baseline.
API Latency vs Target SLA (Non-Zero Baseline)
Service latencies compared against a 250ms target benchmark, rendered in deviation space.
Skeletons indicate runtime fetch or pending data queries.
Handles empty collections ([]) gracefully without crashing.
Graceful failure banner when data source or script fails.
Container-Driven Breakpoints
Diverging Bars fluidly adapts from ultra-wide enterprise monitoring down to narrow 320px mobile displays. Symmetric domain scaling guarantees balanced visual anchor on both sides of the reference line at all widths and heights.
Full categorical tick labels, outward value callouts, and spacious analytical tooltips with raw measurements and derived deviations.
Compact category labels, preserved symmetric domain bounds, and responsive tooltip clamping within container bounds.
Horizontal layout recommended to afford long category names, strict touch-action pan-y preservation, and compact card tooltips with auto-adjustment.
Accessibility & Navigation Standards
Semantic figure region with single tab stop, arrow-key navigation (Left/Right for vertical layout, Up/Down for horizontal layout), Home/End traversal, polite ARIA live announcements, and an offscreen structured HTML table for screen readers.
Container mounts as region with explicit assistive label.
Spatial direction relative to the baseline unambiguously conveys sign even under complete monochromatic rendering. Explicit table columns and legend indicators ensure color is never the sole information carrier.
Embeds visually hidden summary (.sr-only) declaring: “Announces category name, raw value, baseline reference, and signed deviation. Factual accessibility summary details counts above, below, and on reference.”
All initial entrance animations are bypassed immediately when prefers-reduced-motion is detected.
| Key | Action |
|---|---|
| ArrowDown / ArrowRight | Move focus to the next category |
| ArrowUp / ArrowLeft | Move focus to the previous category |
| Home | Jump focus to the first category |
| End | Jump focus to the last category |
| Escape | Clear active category inspection |
Internal Architecture & File Dependencies
Source-first ownership model. Inspect the exact component call tree, dependencies, and full implementation below.
Provides responsive container sizing and design tokens