Skip to content
InsightCharts

Search

Search guides and components

Segmented bar

Splits one whole into proportional segments along a single horizontal bar.

Use when
A compact part-to-whole for cards, table cells and stat rows: budget split, device mix, vote share. The legend carries names in block order.
Avoid when
Comparing compositions across several groups (use bar chart with stack "percent"); more than about 6 parts or many slivers (use bar chart); when the reader should count units (use waffle chart).

Preview

Labour won 411 of 650 seats in the 2024 general election

Seats in the House of Commons by party after the 2024 general election

Source: House of Commons Library · Figures are approximate, for illustration

Composition

Used in

2 molecules and 2 templates use segmented bar.

Molecules

2

A headline number with its composition underneath: one segmented bar and a key giving each part's value and share.

The sheet an infographic is composed on. It paints a full-bleed ground from a poster theme, forces one theme and colour mode on everything inside, and lays out a masthead, a grid of panels and a footer. It can save the whole sheet as one PNG.

Templates

2

A compared with B on one page. It has a headline that states the result, the headline figures mirrored either side of their labels, one hero exhibit that shows both sides, paired exhibits on a shared scale, a verdict callout and a source note.

A vertical infographic in one narrow column. It opens with a big number or a proportion statement (hook), then the hero exhibit, then numbered sections with one exhibit each, a conclusion with an optional link, and sources.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/segmented-bar

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 { SegmentedBar } from "insightcharts";

Examples

Thin, for cards

Mobile accounted for 61% of sessions in the last 30 days

Sessions by device, last 30 days

With highlight

Housing was 33% of US consumer spending in 2023

Share of annual consumer spending, United States, 2023

Source: BLS Consumer Expenditure Survey · Figures are approximate, for illustration

Stress: many parts, long names, slivers

Cardiovascular diseases cause 19.8 million deaths a year

Deaths by cause, world, millions per year

Source: IHME Global Burden of Disease · Rounded, approximate figures for illustration

Props

PropTypeDefaultDescription
namerequiredstringCategory field: one segment per distinct value.
valuerequiredstringValue field.
size"tall" | "thin""tall"28px with shares printed inside where they fit, or 8px unlabelled.
sort"none" | "desc""none"Segment order; the legend follows it.
namesRecord<string, string>Display names for category keys.
Common chart props 29

Every chart built with defineChart accepts these on top of its own props.

PropTypeDescription
dataDataInputRows, CSV text, a URL, { url, path }, an async function, or an Arrow-style table. Omit inside <InsightData>.
transformTransform | Transform[]A pipeline of transforms applied before drawing.
titlestringThe title. One plain statement of what the data shows, with the number and the period ("Monthly churn fell from 4.2% to 2.1% in 2024"), or a plain label ("Monthly churn, 2024"). One clause, no figures of speech.
subtitlestringMeasure, unit, population, period.
sourcestringData source, shown as "Source: ...".
notestringMethod notes or caveats.
heightnumber | stringCSS height of the plot. Default 360.
aspectnumberWidth / height. Overrides height.
highlightstring | string[]The entity (or entities) the title is about. Every other series is drawn in grey.
annotationsAnnotation[]Reference lines, shaded bands and callouts, in data coordinates.
formatFormatSpecHow to print values: "compact", "percent", "currency:USD", "{value} kg", Intl options, or a function.
legendbooleanShow the legend. Default: shown when there are two or more series.
selectboolean | stringMake marks clickable to filter. Inside <InsightData> the selection filters every other chart. Pass a field name, or true to use the chart's category field.
onSelect(values: string[], field: string) => voidCalled with the selected values whenever the selection changes.
optionEChartsOption | ((option: EChartsOption, ctx: BuildContext) => EChartsOption)Deep-merged over the generated ECharts option, or a function that receives and returns it. Use it for ECharts settings no prop covers.
themeThemeInputA theme, or a partial set of tokens merged over the surrounding theme, for this chart only.
modeModeInput"auto" (default) follows the page, "system" follows the OS, or force "light" / "dark".
rendererRendererInput"auto" (default) uses SVG for light charts and canvas for heavy ones.
animatebooleanSet false to disable animation. Reduced-motion preferences are always respected.
lazybooleanMount the chart only when it scrolls near the viewport. Default true.
groupstringLink tooltips with other charts sharing this group id.
exportableboolean | ExportFormat[]Show an export menu: true or a list of formats from png, jpeg, svg, pdf, csv, json.
tablebooleanShow a collapsible "View data" table under the chart.
altstringAccessible description: the chart type and measures, then the main pattern and the notable values.
idstringStable id for this chart's selection in the shared store.
onEventsRecord<string, ChartEventHandler>ECharts event handlers, e.g. { click: (params, chart) => {} }. Prefix a name with zr: to bind to the canvas itself.
onReady(chart: EChartsInstance) => voidCalled with the ECharts instance once it is created.
classNamestringClass name for the outer <figure>.
styleCSSPropertiesInline style for the outer <figure>.