shadcn.io is not affiliated with official shadcn/ui
KPI Bar with Trends Stats Block for React
Four figures for a garden-centre analytics tool in cells that share their hairlines, each with its change on the week before and an area chart that runs to the cell's edges and foot.
Installation
Overview
A KPI bar with trends for React with Base UI. A start-aligned header states the headline number, "Weekly sales rose 6.2% in week 12", and under it four figures (weekly sales, orders, average basket and returning shoppers) sit in cells that share their hairlines, in a band that runs from rail to rail and ends the block. Each cell shows the value (it rolls up once), its label and its change on the week before as an arrow and a signed number. Under them an area chart of the last twelve weeks runs to the cell's side edges and its foot: a thin line in your theme's foreground colour, the last week drawn at full weight and ending on a dot, and a faint fill under the whole line. Every figure, change, headline number and chart is computed from one set of weekly readings, and the average basket is sales divided by orders, so the cells always agree. Four across from lg, two by two below it. For an analytics or shop dashboard that shows the trend with the number.
FAQ
How do I change the figures?
Edit SALES, ORDERS, RETURNING and KPIS at the top of the file. Each KPI is a label, a series of weekly readings (oldest first, one per week), its prefix, suffix and decimals, and a change kind: percent for a share of the week before (+6.2%), count for a difference (+22) or points for rates (+0.5 pts). The value, the change, the chart and the headline's number are read from the series. The average basket is computed from the two series before it.
How are the charts drawn?
Each chart is an SVG path computed when the module loads: the readings are scaled into a 100 by 100 box and the box stretches to the cell (preserveAspectRatio="none" with a non-scaling stroke, so the line stays 1.5 pixels at any width). The line starts at the cell's start edge and ends at its end edge, where the end dot, an HTML element so it stays round, sits just inside. The weeks before are drawn at 35% of the text colour and the last week at full strength. The box is dir="ltr", because time runs from the start to the end in every language.
Why aren't rises green and falls red?
Whether a change is good depends on the figure. The block shows direction with an arrow and a sign, in the text colour, and leaves the judgement to the reader. That keeps it correct in every theme preset and readable without colour.
Is it accessible?
Yes. The figures are a description list: each label is a term, and the value, the change and the chart are its descriptions, so a screen reader hears "Weekly sales, $12,970, +6.2% vs week 11". Each chart is an image whose name gives its first and last readings, its low and its high, week by week. The arrows are hidden from assistive technology because the sign says the same, and values sit in bdi elements for right-to-left pages.
What moves, and what if motion is off?
The values roll up when they scroll into view, and each chart draws from start to end with a CSS clip-path transition, then its end dot appears. With reduced motion the transitions are off and everything simply appears. The chart is complete in either case.
How does it fit on a phone?
Two by two, with the charts still running edge to edge and the comparison on its own line under the change, so the cells of a row match. Each cell lays its parts on rows it shares with the cell beside it (a CSS subgrid), so a wrapped label moves the rows below it in both cells and the charts stay level.
Related
- Pro
Connected KPI Bar Stats
KPI bands and tilesFour headline figures for a subscription analytics tool in cells that share their hairlines from rail to rail, each with its change on the month before and a tiny sparkline of the last twelve months.
- Pro
Sparkline Tile Grid Stats
KPI bands and tilesFour KPI tiles for a subscription-box company, each holding the same twelve weeks as an area sparkline, with one slider that moves a cursor through all four and rewrites their values to the chosen week.
- Pro
Sortable Sparkline Tile Grid Stats
KPI bands and tilesSix web-vitals tiles in one hairline frame, each with a fourteen-day line, its low and high marked by ticks, and a Sort by switch that re-orders them by change, budget used or volatility.
- Pro
Area Chart Hero Stats
Area and lineA rail-to-rail area chart for a farm-shop sales tool: twelve months of sales fading out toward the foot, with the latest month's figure and its change laid over the top corner.
- Pro
Sparkline Hero Metric Stats
Hero metricA hero figure for a cash-planning tool beside its own 90-day trend: the runway in months at the start, and a wide line with its high, its low and today marked.
- $48,110Pro
A revenue banner for a sales dashboard, as a card in card: the figure, a change badge and the comparison at the start, a 24 h and 7 d switch and a bar sparkline at the end, swapping in place.