affectUI › Components › Data display
Metering Chart
Usage per day as soft gradient bars drifting from blue to lilac, with a live bar for today that keeps growing, a Real-time badge and rolling totals.
Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/metering-chart.json · Import from @/components/ui/metering-chart
When to use
- Usage-based billing and metering – API calls, tokens, events, minutes per day
- A usage card where today is still counting and should look alive
- A calm daily bar chart that reads as a whole, with totals above it
When not to use
- Comparing series or periods – use Trend Chart
- Hundreds of days – the bars get too thin; group them into weeks first
Usage
import { MeteringChart } from "@/components/ui/metering-chart";
export function ApiCalls() {
return (
<MeteringChart
title="API calls"
live
period="Sep 1 – Sep 21"
data={[
{ label: "Sep 1", value: 1870 },
{ label: "Sep 2", value: 2290 },
{ label: "Sep 3", value: 2860 },
]}
totals={[
{ label: "Total volume", value: 50390, format: (n) => `$${Math.round(n).toLocaleString()}` },
{ label: "Total events", value: 36000 },
]}
/>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | Heading of the card | |
data | MeteringDay[] | { label, value } per day, oldest first; a missing or broken value leaves an empty slot | |
totals | MeteringTotal[] | { label, value, format? } – figures under the title that roll to their new values | |
period | string | The span on the right, e.g. "Sep 1 – Sep 21" | |
live | boolean | false | The last bar is today and still counting: accent color, a running sheen, a turning spinner in the pink badge |
badge | string | "Real-time" when live | Text next to the title; empty for none |
format | (n: number) => string | 1,284 | Formats the tag and the totals |
axisFormat | (n: number) => string | Shorter numbers for the value axis, e.g. 4.5k | |
colors | string[] | light blue → lilac → mauve | Colors the bars drift through from left to right |
accent | string | "#5e5cff" | Color of the live bar |
height | number | 120 | Height of the plot in px |
emptyText | string | "No usage yet" | Quiet text when there is nothing to draw |
className | string | Extra class on the card |
Keyboard
- Tab: Focus the chart
- ← / →: Move to the previous or next day
- Home / End: Jump to the first day or today
- Esc: Close the tag
Accessibility
- The chart is one focusable stop, readable with the arrow keys; the tag is a polite live region
- Totals are read out with their final value, never a number on its way
Responsive
- Fills its container; bars stay 11px wide and thin out on narrow cards, the period moves under the title
- Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
Requirements
- React 19
Related
- Trend Chart – The chart on its own for any card or layout – line, area, bars or a sparkline from the same data, with a tooltip, this period against the last, and charts that follow the same day together
- Stat Card – One number with its label, how it changed – green or red, lower can be better – and room for a chart below or beside it; numbers roll, the card can be a link
- Usage Meter – Plan usage and AI credits – a stacked credits meter by category, daily sparkline, limits and a button that speaks up near the limit