SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Chart

The Chart namespace's compound parts, covering Cartesian series (Chart, Chart.Line, Chart.Area, Chart.Bar) and the independent Chart.Pie root.

Apr opened: 1,840Apr resolved: 1,710May opened: 2,120May resolved: 2,040Jun opened: 2,460Jun resolved: 2,180Jul opened: 2,310Jul resolved: 2,290Aug opened: 1,980Aug resolved: 1,960Sep opened: 2,640Sep resolved: 2,470

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
tsx
<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.

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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
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.

  • Chart
  • Chart.LineRenders a line series: a stroked, aria-hidden <path> connecting points via 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> tracing points and closing down to baseline, 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 at y, with label set 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, label tagged 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

Last week 8:00, 170 msLast week 10:00, 174 msLast week 12:00, 186 msLast week 14:00, 177 msLast week 16:00, 171 msLast week 18:00, 168 msToday 8:00, 182 msToday 10:00, 190 msToday 12:00, 342 msToday 14:00, 214 msToday 16:00, 185 msToday 18:00, 179 ms

Solid: today. Dashed: the same hours last week.

View code
tsx
<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

May: no dataJun: no dataJul: $1,240Aug: $2,310Sep: $2,980Oct: $3,620
View code
tsx
<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

8:00, 182 ms10:00, 190 ms12:00, 268 ms16:00, 214 ms18:00, 185 ms

The line breaks where no check ran; the hatched band marks those hours as unknown.

View code
tsx
<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.

PropTypeDefaultRequiredDescription
widthnumber—YesPixel 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.
heightnumber—YesPixel height of the chart's internal coordinate space — the value every nested series' y positions are mapped onto.
xDomainreadonly [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.
yDomainreadonly [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

PropTypeDefaultRequiredDescription
pointsreadonly LinePoint[]—YesThe 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.
colorColor—NoCategorical color. Defaults to DEFAULT_LINE_COLOR.
comparisonboolean—NoDraws 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.
markerCountnumber—NoApproximate 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

PropTypeDefaultRequiredDescription
pointsreadonly AreaPoint[]—YesThe 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.
colorColor—NoCategorical color. Defaults to DEFAULT_AREA_COLOR.
baselinenumber—NoThe yDomain value the filled region closes down (or up) to — typically the value axis' zero line. Defaults to DEFAULT_AREA_BASELINE.
markerCountnumber—NoApproximate 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

PropTypeDefaultRequiredDescription
ynumber—YesThe value the line marks, mapped across the ancestor Chart's yDomain.
labelstring—NoText 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

PropTypeDefaultRequiredDescription
fromnumber—YesWhere the range starts, mapped across the ancestor Chart's xDomain.
tonumber—YesWhere the range ends, on the same scale as from.
labelstring—NoText 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"—NoColour of the edge rules, the label tag and, for variant="fill", the shading.

Also accepts everything in Omit<TagProps<"g">, "children">.

Chart.Pie

PropTypeDefaultRequiredDescription
datareadonly PieDatum[]—YesThe wedges to draw, in draw order. Each entry's position in this list picks its default color when its own color is omitted.
widthnumber—YesPixel 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.
heightnumber—YesPixel height of the chart's internal coordinate space, on the same terms as width.
innerRadiusnumber—NoPixel 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

PropTypeDefaultRequiredDescription
datareadonly BarRow[]—YesRows to plot, one band per row along the category axis, in draw order.
seriesreadonly string[]—YesOrdered 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.
widthnumber—YesPixel 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.
heightnumber—YesPixel height of the chart's internal coordinate space, on the same terms as width.
domainreadonly [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.
tickCountnumber—NoApproximate number of horizontal gridlines spanning domain. Defaults to DEFAULT_BAR_TICK_COUNT.
categoryGapnumber—NoFraction of each category band reserved as a gap from its neighbors. Defaults to DEFAULT_CATEGORY_GAP.
seriesGapnumber—NoFraction 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

NameValuesWhat it decides
Tone"brand" | "neutral" | "success" | "warning" | "danger"Semantic role a Chart.Threshold or Chart.Band is drawn in.
@sdxc/ui

Can’t find it? Contact us