Chart
The Chart namespace's compound parts, covering Cartesian series (Chart, Chart.Line, Chart.Area, Chart.Bar) and the independent Chart.Pie root.
Backlog is growing. September opened 2,640 and resolved 2,470. Tab into the plot to hear each bar, or a legend row to strike a series out.
View code
<div mix={[vstack({ gap: 3, align: "stretch" }), is("100%"), maxIs("32rem")]}>
<Chart.Bar
aria-label="Tickets opened and resolved, April through September"
width={480}
height={200}
domain={[0, 3000]}
tickCount={4}
series={["opened", "resolved"]}
data={VOLUME.map((row) => ({
category: row.month,
values: {
opened: { value: row.opened, label: `${row.month} opened: ${COUNT.format(row.opened)}` },
resolved: {
value: row.resolved,
label: `${row.month} resolved: ${COUNT.format(row.resolved)}`,
},
},
}))}
/>
<Chart.Legend aria-label="Series shown">
<Chart.Legend.Item color={1} defaultChecked mix={[ariaChecked()]}>
Opened
</Chart.Legend.Item>
<Chart.Legend.Item color={2} defaultChecked mix={[ariaChecked()]}>
Resolved
</Chart.Legend.Item>
</Chart.Legend>
<div mix={[hstack({ gap: 0, align: "center" })]} aria-hidden="true">
{VOLUME.map((row) => (
<span
key={row.month}
mix={[grow(), basis("0%"), textAlign("center"), text("xs"), fg("neutral.muted")]}
>
{row.month}
</span>
))}
</div>
<p mix={[text("sm"), fg("neutral")]}>
<span mix={[weight("medium")]}>Backlog is growing.</span> September opened 2,640 and
resolved 2,470. Tab into the plot to hear each bar, or a legend row to strike a
series out.
</p>
</div>Demo apps
Whole pages built only from @sdxc/ui, each for an invented product with its own palette and type. They open in a new tab.
- Food deliveryBocadoBocado, an invented food delivery app: restaurants by cuisine and delivery time, search with filters, menus with options, a cart, checkout and live order tracking on a drawn map./showcase/bocado/demo
- Issue trackerCairnCairn, an invented issue tracker: grouped issue lists with filters in the address, a drag-and-drop board, projects on a roadmap, cycles with burn-up charts and an inbox./showcase/cairn/demo
- Social networkChorusChorus, an invented social network: a live timeline with pictures, link cards, polls and threads, profiles, grouped notifications, search and messages./showcase/chorus/demo
- Code hostDeltaDelta, a code host whose one repository is its own source: a file tree beside the code, line links, blame and the commits list, every file and commit read from git when the site is built./showcase/delta/demo
- Online storeHangwellHangwell, an invented poster shop: collections with facet filters, product pages with format, size and frame pickers and a room preview, a bag, a checkout that adapts to print files, order tracking, downloads and returns./showcase/hangwell/demo
- CMSInkwellInkwell, a demo CMS built from @sdxc/ui/app: posts with count tabs and quick edit, an editor with a quiet save status and a loud Publish, media and settings./showcase/inkwell/demo
- Music streamingMurmurMurmur, an invented music service: home shelves, search by genre, a library, albums, playlists and artists, with a player that keeps playing while you browse./showcase/murmur/demo
- Team chatParleyParley, an invented team chat: channels and direct messages with unread and mention badges, threads, reactions, edits, pins, search, a quick switcher and teammates who type and post live./showcase/parley/demo
- Photo and video networkPinholePinhole, an invented social network for photographs and short videos: a feed under a story tray, full-screen stories, a vertical reels feed, profiles with highlights, Explore and posts with comments./showcase/pinhole/demo
- Ops dashboardPulsePulse, an invented ops dashboard: Northwind's services with live filters, a peek sheet and a bulk bar, metrics that switch one chart, incidents, deploys and settings./showcase/pulse/demo
- Support inboxRelayRelay, an invented support inbox: mailboxes, conversations and the open conversation on one screen, with contacts, reports and settings./showcase/relay/demo
- CalendarSundialSundial, an invented calendar: day, week and month views, an agenda, events you drag, resize and create on the grid, a second time zone, and a find-a-time view across a team in five zones./showcase/sundial/demo
- Chat assistantTernTern, an invented chat assistant: conversations with streamed replies, code and tables, projects, a canvas, sharing and settings./showcase/tern/demo
- Banking & budgetsTuppenceTuppence, an invented personal bank: multi-currency accounts, a statement by day with search and splits, spending and budgets, savings pots, bills ahead, cards that freeze and a transfer flow, all with fake money./showcase/tuppence/demo
- Streaming serviceVesperVesper, an invented streaming service: profiles, a home of sideways shelves under a billboard, series with seasons and episodes, search, My List and a theater player./showcase/vesper/demo
- Travel bookingWayfernWayfern, an invented travel app: stays, flights, cars and packages from one search, results on a real map, seat maps and boarding passes, and one itinerary of trips that exports to calendars./showcase/wayfern/demo
Every demo, landings and docs sites alike, is listed in the showcase.
Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { Chart } from "@sdxc/ui/app";Renders a chart's coordinate space: a responsive <svg> whose viewBox
comes from width/height, shared via context so nested series share one scale. Markers
and strokes on its edges paint in full. A paired Chart.Legend renders as its later sibling.
Composition
The parts the component publishes, each a static property of the host.
ChartChart.LineRenders a line series: a stroked,aria-hidden<path>connectingpointsvia linearScale and linePath, plus a focusable marker with a<title>, sampled via ticks for manageable density.Chart.AreaRenders an area series: a filled,aria-hidden<path>tracingpointsand closing down tobaseline, mapped through linearScale and areaPath, plus a focusable marker sampled via ticks.Chart.ThresholdMarks a value the series should stay under or over: a dashed line across the plot aty, withlabelset at its end.Chart.BandMarks a stretch of the x axis (an incident, a deploy, or hatched, a gap with no data): a light shade, dashed edge rules,labeltagged at its top start, or top end once it starts past the plot's middle.Chart.PieRenders a pie or donut chart: an independent<svg>root, since a circular layout shares no domain with a Cartesian Chart.Chart.BarRenders a categorical bar chart: an independent<svg>root, since a band axis shares no continuous domain with a Cartesian Chart.
Examples
Comparison, threshold and incident band
Solid: today. Dashed: the same hours last week.
View code
<Chart width={480} height={200} xDomain={[0, 11]} yDomain={[0, 400]} aria-label="p95 latency today against last week">
<Chart.Band from={3.5} to={5.5} label="Incident #42" />
<Chart.Line points={points(LAST_WEEK, "Last week")} comparison />
<Chart.Line points={points(TODAY, "Today")} />
<Chart.Threshold y={300} label="SLO 300 ms" tone="warning" />
</Chart>Hatched periods with no data
View code
<Chart.Bar
width={480}
height={180}
domain={[0, 4000]}
aria-label="Revenue by month, May to October"
series={["revenue"]}
data={REVENUE.map((row) => ({
category: row.month,
values: {
revenue: {
value: row.amount,
label: row.amount === null ? `${row.month}: no data` : `${row.month}: ${DOLLARS.format(row.amount)}`,
},
},
}))}
/>Gaps with no data
The line breaks where no check ran; the hatched band marks those hours as unknown.
View code
<Chart width={480} height={200} xDomain={[0, 11]} yDomain={[0, 400]} aria-label="p95 latency today, with a gap in the checks">
<Chart.Band from={4.5} to={7.5} label="No data" variant="hatched" />
<Chart.Line points={points(LATENCY)} />
<Chart.Threshold y={300} label="SLO 300 ms" tone="warning" />
</Chart>Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
width | number | — | Yes | Pixel width of the chart's internal coordinate space — the value every nested series' x positions are mapped onto. The <svg> renders at its container's full size, scaling this space while preserving aspect ratio. |
height | number | — | Yes | Pixel height of the chart's internal coordinate space — the value every nested series' y positions are mapped onto. |
xDomain | readonly [number, number] | — | Yes | [start, end] bounds of every nested series' horizontal data values, mapped across width and shared through context so every series lines up on the same horizontal scale. |
yDomain | readonly [number, number] | — | Yes | [start, end] bounds of every nested series' vertical data values, mapped across height. start maps to the coordinate space's bottom edge and end to its top, matching a value axis growing upward against SVG's y. |
Also accepts everything in Omit<TagProps<"svg">, "viewBox" | "width" | "height">.
Chart.Line
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
points | readonly LinePoint[] | — | Yes | The series' data points, in draw order along x. The plotted path connects every point with data, breaking at each null one; the accessible markers render on a representative spread of them, chosen through markerCount. |
color | Color | — | No | Categorical color. Defaults to DEFAULT_LINE_COLOR. |
comparison | boolean | — | No | Draws the series as the comparison period, dashed and muted behind the current one, in --ui-chart-comparison-color with --ui-chart-comparison-dash; color is unused. |
markerCount | number | — | No | Approximate number of accessible, hoverable markers placed along points. Each marker snaps to the point closest to one of this many evenly spread "nice" values across the ancestor Chart's xDomain. |
Also accepts everything in Omit<TagProps<"g">, "children" | "points">.
Chart.Area
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
points | readonly AreaPoint[] | — | Yes | The series' data points, in draw order along x. The filled region traces every point given here before closing down to baseline; markers render on a representative spread of them, chosen through markerCount. |
color | Color | — | No | Categorical color. Defaults to DEFAULT_AREA_COLOR. |
baseline | number | — | No | The yDomain value the filled region closes down (or up) to — typically the value axis' zero line. Defaults to DEFAULT_AREA_BASELINE. |
markerCount | number | — | No | Approximate number of accessible, hoverable markers placed along points. Each marker snaps to the point closest to one of this many evenly spread "nice" values across the ancestor Chart's xDomain. |
Also accepts everything in Omit<TagProps<"g">, "children" | "points">.
Chart.Threshold
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
y | number | — | Yes | The value the line marks, mapped across the ancestor Chart's yDomain. |
label | string | — | No | Text set at the line's end ("SLO 300 ms"), also its accessible name. |
tone | "brand" | "neutral" | "success" | "warning" | "danger" | — | No |
Also accepts everything in Omit<TagProps<"g">, "children">.
Chart.Band
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
from | number | — | Yes | Where the range starts, mapped across the ancestor Chart's xDomain. |
to | number | — | Yes | Where the range ends, on the same scale as from. |
label | string | — | No | Text set in a tag at the band's top start ("Incident #42", "Deploy"), also its accessible name. The tag renders at the same size however wide the chart is drawn. |
variant | "fill" | "hatched" | — | No | "hatched" draws the range with the hatch Chart.Bar uses for a null value, so a stretch with no data (an outage window nothing was recorded for) reads as unknown. |
tone | "brand" | "neutral" | "success" | "warning" | "danger" | — | No | Colour of the edge rules, the label tag and, for variant="fill", the shading. |
Also accepts everything in Omit<TagProps<"g">, "children">.
Chart.Pie
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
data | readonly PieDatum[] | — | Yes | The wedges to draw, in draw order. Each entry's position in this list picks its default color when its own color is omitted. |
width | number | — | Yes | Pixel width of the chart's internal coordinate space that viewBox maps onto. The rendered <svg> fills 100% of the host's own inline size, scaled to fit while preserving this aspect ratio against height. |
height | number | — | Yes | Pixel height of the chart's internal coordinate space, on the same terms as width. |
innerRadius | number | — | No | Pixel distance from center to every wedge's inner edge, in the same coordinate space as width/height. A positive value smaller than the chart's outer radius produces a donut with a hole that size. |
Also accepts everything in PieAngles.Options.
Also accepts everything in Omit<TagProps<"svg">, "children" | "viewBox" | "width" | "height">.
Chart.Bar
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
data | readonly BarRow[] | — | Yes | Rows to plot, one band per row along the category axis, in draw order. |
series | readonly string[] | — | Yes | Ordered series keys plotted within every row's band. A key's position in this list is both the stable index stamped onto data-series-index and its slot in the --ui-chart-1–--ui-chart-8 palette, wrapping past it. |
width | number | — | Yes | Pixel width of the chart's internal coordinate space that viewBox maps onto. The rendered <svg> fills 100% of the host's own inline size, scaled to fit while preserving this aspect ratio against height. |
height | number | — | Yes | Pixel height of the chart's internal coordinate space, on the same terms as width. |
domain | readonly [number, number] | — | Yes | [start, end] bounds of every bar's value, mapped across height. start maps to the bottom edge and end to the top, matching the same upward-value convention Chart.Props.yDomain uses against SVG's y. |
tickCount | number | — | No | Approximate number of horizontal gridlines spanning domain. Defaults to DEFAULT_BAR_TICK_COUNT. |
categoryGap | number | — | No | Fraction of each category band reserved as a gap from its neighbors. Defaults to DEFAULT_CATEGORY_GAP. |
seriesGap | number | — | No | Fraction of each category's own band reserved as a gap between its series' bars — most bar charts plot a single series per category, with no neighboring bar to gap against. |
Also accepts everything in Omit<
TagProps<"svg">,
"children" | "viewBox" | "width" | "height"
>.
Types
| Name | Values | What it decides |
|---|---|---|
Tone | "brand" | "neutral" | "success" | "warning" | "danger" | Semantic role a Chart.Threshold or Chart.Band is drawn in. |