Skip to main content

Formatting

Chart Parts

The format engine: ChartValueFormat's object-spec form, YAxis unit/unitOn, and the XAxis date-format ladder across a short and a long time span. GermanLocale shows charts following a de-DE LocaleProvider.

Examples

9 live examples

With Preset Format

The `"compact"` preset string on the same axis/data, for comparison.

Axis Unit

`YAxis unit="km"` paints the unit on the LAST tick only (the default).

Date Ladder Short Span

A 36-hour series: the date ladder resolves to the "hour" rung on its own (no `dateFormat` override) — every tick reads a time of day, not a date. Fluid (`w-full`, no max-width) like `Charts/Axes`' `WidthDerivedTicks` — resize the canvas to watch the tick count (and, on a longer span, the ladder rung) track the plot's own pixel width, not the viewport.

Date Ladder Long Span

A ten-year DAILY series, fluid width like `Charts/Axes`' `WidthDerivedTicks` — resize the canvas to watch RM-108's width-derived tick target carry the RM-109 date ladder with it. The year rung's abbreviation follows the axis's own room, not the tick count: at 380 px `XAxis` is RM-107's `sm` (narrow, `cramped`) density, so `dateFormatForSpan` abbreviates — `’16 ’18 ’20 ’22 ’24`, a d3-"nice" 2-year calendar step; at 900 px there is room to spell the year out — `2016 2017 … 2025`, a 1-year step. Every label lands on a real calendar-year boundary (d3's own `.ticks()`, via `buildDomainTicks`'s `preferCalendarAlignment`) — no duplicate or skipped year within the step. The x axis itself stays visible at narrow — RM-107's `sm` density drops the value axis and legend only, never the category axis.

Date Format Override

A caller-supplied `dateFormat` preset pins one rung regardless of span — here "month" on the same ten-year daily series `DateLadderLongSpan` shows as "month", to demonstrate the override winning outright.

Legend Object Spec

`ChartLegend`'s `valueFormat` resolves as a SET across every item (#250) — with an object spec, every value shares the same abbreviate/decimals decision instead of compacting independently.

Metric Card Object Spec

`MetricCard`'s `valueFormat` (`@elabs-ai/components-ui`) accepts the same object-spec shape as the chart engine — a deliberate twin (`packages/ui/src/lib/compact-number.ts`), since `ui` cannot import `charts`.

German Locale

Charts under `<LocaleProvider locale="de-DE" messages={…}>` (RM-187): every number follows the provider's locale (`1.234`, `7,5`, `1.000`) and every chart word the app supplies in `messages` replaces the English default. No chart takes a prop for it.