Skip to content
TrademarkTrademark
Docs
Data

Recipes

Updated: November 12, 2026
View on GitHub

Each recipe is a pattern you can paste and adapt. They use only @once-ui-system/core and @once-ui-system/core/data.

Dashboard grid

Charts fill their container, so a dashboard is a Grid of them. Give every chart in a row the same height so their plots line up, and let the grid collapse to one column on small screens.

KPI tiles

A tile is a number, its change and the shape behind it: a Sparkline, not a full chart. Keep full charts for the questions a reader explores; tiles are for glancing.

Colour the change by what it means for the business, not by its sign: more refunds is up and bad.

Fetch in a server component

The charts render on the server, so the page can query and pass the rows straight in. The first HTML holds the drawn chart, with no loading spinner and no client fetch.

Rows cross to the client as JSON, so send what the chart draws, not whole database records. Date values arrive as Dates; numbers stored as strings (Postgres numeric) need a Number() first. Keep function props out of server components: see Numbers and dates.

This period against the last

Draw the comparison as a quiet reference: last period in gray, this period in a colour.

Signups, this month against last
Signups, this month against last: data
dayLast monthThis month
14048
54655
105261
154970
205874
2561
3064
020406080151015202530

Align the two periods by position (day 1, day 2…), not by date, so they share the axis. The current period stops where today is: leave its later values out instead of writing 0, and the line ends there.

Top N and other

A pie past five slices stops being readable. Keep the biggest and add up the rest:

Traffic by source
Traffic by source: data
nameSessionsShare
Search42.1K41.9%
Direct31.8K31.6%
Social12.4K12.3%
Email8.3K8.3%
Other5.9K5.9%

gray marks "Other" as the leftovers, not a fifth source to compare.

Target and actual

LineBarChart draws its first series as a line and its second as bars, on one axis: the target as the line, the actuals as bars.

Live data

For a chart that updates every second, keep the x range fixed so the axis doesn't rescale on each sample. useStreamingViewport buffers the samples and pans the visible window; the live examples on LineChart show it with the animation tuned to glide, and turned off to snap.

Let the reader switch views

LineChart and BarChart take the same props, so one set of props can draw either. A SegmentedControl picks which.

Theme switch for charts

useDataTheme() reads the chart settings and setChartOptions changes them for every chart under the provider. A new mode is also remembered in the browser.

Edit this page on GitHub