Skip to content
Thrum
Docs · 09 of 09All pages

Working with data

Data shapes, missing values, formatting numbers, server components.

Data components (charts, numbers, meters, live feeds and dashboards) take plain serialisable data props: numbers, strings, arrays and objects, with no render props and no formatter functions. That keeps the rules consistent across every visualisation and lets a server component pass its data straight down. Interactive UI primitives (dialogs, menus, cards, tabs and forms) use standard composable JSX parts instead. This page covers data shapes, missing values, number formatting, and large series.

Data shapes

A chart of one series takes its points as data, in the order they are drawn: oldest first for a series over time. The calendar heatmap places each day by its date, so its data can be in any order. A chart of several series takes labels and series. A component that shows one figure takes a value. The table lists every required prop except the label or title.

ComponentPropType
Choice cardChoiceCard: valuestring
ComboboxComboboxItem: valueComboboxOption
Inline editaria-labelstring
Input OTPInputOTPSlot: indexnumber
Mask inputmaskstring
Multi selectoptionsreadonly MultiSelectOption[]
Radio groupRadioGroupItem: valuestring
SelectSelectItem: valuestring
Copy buttonvaluestring
Icon buttonaria-labelstring
Segmented controloptionsreadonly SegmentedControlOption[]
Toggle groupToggleGroupItem: valuestring
Command paletteCommandItem: childrenReactNode
Confirm popoverchildrenReactElement
Context menuContextMenuRadioItem: valuestring
Dropdown menuDropdownMenuRadioItem: valuestring
Hover cardHoverCardTrigger: hrefstring
MenubarMenubarRadioItem: valuestring
Navigation menuNavigationMenuLink: hrefstring
Notification centernotificationsreadonly NotificationItem[]
PaginationpageCountnumber
StepperStepperItem: titleReactNode
Table of contentsitemsreadonly TableOfContentsItem[]
TabsTabsTrigger: valuestring | number
TabsTabsContent: valuestring | number
Data tablecolumnsreadonly DataTableColumn[]
Data tablerowsreadonly DataTableRow[]
Data tablecaptionstring
Diff viewerbeforestring
Diff viewerafterstring
Filter barfieldsreadonly FilterField[]
JSON viewervalueJsonValue
KbdShortcut: keysstring
Sortable listitemsreadonly SortableItem[]
Transfer listitemsTransferItem[]
Tree viewitemsreadonly TreeNode[]
Virtual listitemsreadonly VirtualListItem[]
Chat messageChatMessageTime: dateTimeDate | string
Chat messageChatMessageFile: namestring
Chat messageChatMessageStatus: status"sending" | "sent" | "failed"
Image zoomsrcstring
Image zoomaltstring
QR codevaluestring
Reasoning panelstepsreadonly ReasoningStep[]
Tool call cardnamestring
Animated numbervaluenumber
Stat cardvaluenumber
Trend badgevaluenumber | null
Area chartdatareadonly AreaChartPoint[]
Bar chartdatareadonly BarChartPoint[]
Bar listdatareadonly BarListItem[]
Bullet chartmeasuresreadonly BulletChartMeasure[]
Calendar heatmapdatareadonly CalendarHeatmapDay[]
Category bardatareadonly CategoryBarSegment[]
Chart legenditemsreadonly ChartLegendItem[]
Chart tooltipChartTooltip: xnumber
Chart tooltipChartTooltip: ynumber
Chart tooltipChartTooltip: widthnumber
Chart tooltipChartTooltipRow: labelReactNode
Chart tooltipChartTooltipRow: valueReactNode
Chart tooltipChartTooltipTotal: valueReactNode
Cohort gridperiodsreadonly string[]
Cohort gridcohortsreadonly CohortGridCohort[]
Combo chartlabelsreadonly string[]
Combo chartbarsreadonly ComboChartSeries[]
Donut chartdatareadonly DonutChartSegment[]
Funnel chartdatareadonly FunnelChartStage[]
Heatmaprowsreadonly string[]
Heatmapcolumnsreadonly string[]
Heatmapvaluesreadonly (readonly (number | null)[])[]
Histogramvaluesreadonly (number | null)[]
Line chartlabelsreadonly string[]
Line chartseriesreadonly LineChartSeries[]
Live chartdatareadonly LiveChartPoint[]
Metric comparisoncurrentnumber | null
Metric comparisonpreviousnumber | null
Radar chartaxesreadonly string[]
Radar chartseriesreadonly RadarChartSeries[]
Radial bar chartdatareadonly RadialBarChartItem[]
Scatter chartseriesreadonly ScatterChartSeries[]
Sparklinedatareadonly (number | null)[]
Stacked bar chartlabelsreadonly string[]
Stacked bar chartseriesreadonly StackedBarChartSeries[]
Status trackerdatareadonly StatusTrackerBlock[]
Treemapdatareadonly TreemapNode[]
Waterfall chartdatareadonly WaterfallChartStep[]
Gaugevaluenumber | null
Progress barvaluenumber | null
Ring metervaluenumber
Usage meterusednumber
Usage meterlimitnumber
Activity feeditemsreadonly ActivityFeedItem[]
Image comparebeforeReactNode
Image compareafterReactNode
MarqueechildrenReactNode
Text scramblechildrenstring
Text shimmerchildrenReactNode
Ticker tapeitemsreadonly TickerTapeItem[]
App shellworkspaceAppShellWorkspace
App shellgroupsreadonly AppShellNavGroup[]
Chat threadmessagesreadonly ChatThreadMessage[]
Finance dashboarddataFinanceDashboardData
KPI griditemsreadonly KpiGridItem[]
Metric tablecolumnsreadonly MetricColumn[]
Metric tablerowsreadonly MetricRow[]
Metric tablecaptionstring
Onboarding checkliststepsreadonly OnboardingStep[]
Ops monitoring dashboarddataOpsMonitoringData
SaaS metrics dashboarddataSaasMetricsDashboardData
Sales dashboarddataSalesDashboardData
Support dashboarddataSupportDashboardData
Web analytics dashboarddataWebAnalyticsDashboardData

Where the type has a name, it is exported from the component's file. The area chart's point, for example:

Type
type AreaChartPoint = {
  label: string;        // axis name
  value: number | null; // null = gap
};
Sample
[
  { label: "Mon", value: 120 },
  { label: "Tue", value: 180 },
  { label: "Wed", value: null },
  { label: "Thu", value: 260 },
]

The page of each component has its shape and a sample next to the full list of props. Every chart and graphic also needs a label that says what the data measures.

You should see

A component never throws on awkward data. An empty list shows “No data” in a chart (set your own text with emptyLabel). One point, a flat series and negative values all draw.

Missing values

A missing value is null. The line breaks there and resumes at the next real value. Nothing is drawn across the gap, because a line through it would show a reading that was never taken.

A gap
const data = [
  { label: "Mon", value: 120 },
  { label: "Tue", value: null }, // no reading on Tuesday
  { label: "Wed", value: 260 },
];
  • Do not send 0 for “no reading”. Zero is a reading, and the chart draws it.
  • Do not send NaN or undefined. Convert them to null where you load the data.
  • A gap can be the first or the last point. In the area chart, a point with a gap on both sides is drawn as a dot.
  • In readouts and in the data table, a missing value is written as a dash.

Formatting numbers

Pass format, an Intl.NumberFormatOptions object. The component applies it everywhere it writes a number: on the axis, in the readout, and in the table for screen readers.

Format
<AreaChart
  data={data}
  label="Response time"
  format={{ style: "unit", unit: "millisecond" }}
/>

These are common options, with what they print:

formatValue, and what prints
Default: compactnot set1283112.8K
Currency{ style: "currency", currency: "USD" }12831$12,831.00
Currency, compact{ style: "currency", currency: "USD", notation: "compact" }12831$13K
Whole currency{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }12831€12,831
Percent{ style: "percent", maximumFractionDigits: 1 }0.18418.4%
Plain, with separators{ maximumFractionDigits: 0 }1283112,831
Unit{ style: "unit", unit: "millisecond" }412412 ms
Unit, one decimal{ style: "unit", unit: "gigabyte", maximumFractionDigits: 1 }1.5361.5 GB
Another locale{ style: "currency", currency: "EUR" }locale="de-DE"12831.512.831,50 €
  • With no format, numbers are compact with at most one decimal.
  • A percent value is a fraction: pass 0.184 for 18.4%.
  • Put the unit in format or in label, so a number never stands alone.
  • format is an object, not a function, so it can cross from a server component to the browser.

Locale, and why it is fixed

Numbers are formatted for en-US unless you pass locale. The default is fixed on purpose. A component renders twice, once on the server and once in the browser, and both must print the same text. If each side used its own default locale, a server in one country and a visitor in another would print “12,831” and “12.831”, and React would report a hydration mismatch.

To format for your visitor, decide the locale once, on the server (from the URL, the account or the request), and pass the same string to every component: locale="de-DE".

Passing data from a server component

Component files start with "use client", and every data prop is serialisable. Load the data in a server component and pass it down:

app/dashboard/page.tsx
// app/dashboard/page.tsx: a server component
import { AreaChart } from "@/components/ui/area-chart";
import { getDailyRevenue } from "@/lib/queries"; // your own data access

export default async function Page() {
  const rows = await getDailyRevenue();
  const data = rows.map((row) => ({ label: row.day, value: row.total }));

  return (
    <AreaChart
      data={data}
      label="Revenue"
      format={{ style: "currency", currency: "USD", notation: "compact" }}
      className="h-64"
    />
  );
}
  • Shape the data on the server. Send the chart only label and value, not whole database rows: everything you pass is sent to the browser.
  • Callbacks such as onActiveChange are the one kind of prop a server component cannot pass. Use them from a client component.
  • A chart with axes draws once it has measured its container in the browser. Before that it holds its final size, empty, so nothing moves when the data appears.

Large series

  • Components are built to draw from 2 to 500 points. A chart has more points than pixels long before that causes trouble: at 600 px wide, 500 points is already less than 2 px each.
  • Every point is a segment of the line and a row in the hidden data table. A series of many thousands makes both heavy, and a screen reader user has to move through all of it.
  • There is no built-in down-sampling. Aggregate where the data lives: minutes into hours, hours into days. Choose the step so the chart gets a few hundred points at most.
  • Axis names thin themselves to what fits. The area, line and stacked bar charts always keep the first and the last; the bar chart keeps the first and then every few. The cursor still stops on every point.
  • When new data has the same number of points, the shape morphs. When the number changes, the chart switches at once. For a live series, keep a fixed window (the last 60 readings) to get the morph.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor