Docs
Data

Live Stat

A metric tile whose value rolls with a spring, with a delta chip and a sparkline you scrub to read any point live.

$npx swiftpieces add LiveStat
Try it in the Playground Use it on a real screen, take it apart, remix it, and copy the SwiftUI. No account needed.
Free · MIT + Commons ClauseiOS 17.0+Liquid Glassstatkpisparklinescrubtilenumbers
Type
LiveStat
Files
LiveStat.swift
Depends on
Nothing (Apple frameworks only)
Version
2.2.1
In a full screen · SwiftPieces ProDashboardA home dashboard with a collapsing greeting, live metrics, a scrubbable chart and activity.

KPI tile with a rolling value, delta chip, and a scrubbable sparkline that expands on press. The tile is a liquid glass panel. While you scrub, a glass flag buds out of the panel's top edge above the point under your finger, joined to the panel by a neck, and shows the change from that point to the latest one. It rides along the edge with the finger and melts back into the panel on release.

Notes

  • The tile is a liquid glass panel: neutral glass by default, tinted with the block's color for .block(_:). The value is an Animatable text in semibold 40 pt display type with dimmed decimals. A spring with no bounce interpolates real numbers through your format, so a roll from rest never shows a value past the one it is heading to. In-flight frames round to the last place the target shows, measured in the format's own terms, so a whole-number format never flashes a long fraction mid-roll and a .percent heading for 3.2% passes 1.6% on the way; a .scale or compact notation rolls the same way. At rest the figure is exactly what your format prints.
  • On first appearance the value counts up as the line draws on, and the dot drops onto the tip once the line has reached it.
  • The tile is a weighted card: it dips about 2.5 pt per edge toward your thumb and its shadow flattens. Held for 280 ms anywhere on a tile with a line, it keeps sinking a point deeper while the hold arms, then springs back up as the dot catches the line at the point nearest your finger with a pop and a soft tap. While you scrub, a rule and the lifted dot sit on the nearest point at every frame, the value retargets with a short roll, and .selection ticks at each point after the first. A glass flag buds out of the panel's top edge right above the point, out of the finger's way, and rests a neck's width above it, joined by a liquid neck: it shows the change from that point to the latest one, tinted sage for a rise and red for a fall, and rides along the edge with the finger without easing after it. Release rolls back to the live value, the flag's tint drains as it melts back into the panel, and the dot grows back on the latest point with visible give. The flag reaches about 32 pt above the tile, over whatever sits there, for as long as you scrub.
  • A plain tap opens the tile like a drawer: the same line grows into a 120 pt chart, with its dot and a dashed baseline at the first value riding the new scale, the baseline fading in a beat behind. The card's edge uncovers a low and high row as it opens, and closing is a little quicker. Tiles around it make room on the same spring. Moving more than 10 pt before the hold completes cancels both, so the tile can live in a scrolling grid, and a touch the system cancels lets go without expanding.
  • The delta is a tinted chip with ink on the panel: sage for up, red for down. It is a fill rather than a glass shape of its own, so the tile reads as one surface. It dims while you scrub, while the flag speaks for the point. Under Increase Contrast it gains a 1 pt outline.
  • The tile holds up at half a phone's width and at large text sizes. When the label and the chip don't fit side by side, the chip moves under the label and a long label wraps instead of truncating; the chip always stays on one line. A figure too wide for the tile shrinks to fit rather than losing digits, to the same smallest size at every Dynamic Type size, and in a narrow tile the expanded low and high row stacks into a column.
  • Style: .standard is a neutral glass tile (its background is .clear); .block(_:) tints the glass with a color block and turns the value, line, and dot to ink, with the delta and a moving flag as ink pills. tint overrides the sparkline color. Every string and symbol is semibold; size sets the hierarchy.
  • Under Reduce Motion the press dims the tile and flattens its shadow without scaling or sinking, the value and line appear without the count-up and draw-on, each roll shortens to a quarter second, the dot and rule fade instead of scaling, the flag fades in and out in place above the tile instead of budding, and the drawer opens and closes in about 0.2 s with fades. Under Reduce Transparency the glass draws solid. Haptics are unchanged. VoiceOver reads label and value, double-tap expands, and swipe up or down scrubs history; swiping up past the latest point returns to the live value, which then follows new values again.
  • A full dashboard screen ships in SwiftPieces Pro (dashboard-screen).

Usage

LiveStatExample().preferredColorScheme(.light)

Parameters

ParameterDescription
labelMetric name shown above the value.
valueCurrent value. Changing it rolls the number from the previous one.
formatNumber format for the value, for example .number, .percent or .currency(code: "USD"). Defaults to .number.
deltaOptional fractional change (0.12 is +12%) shown as a tinted chip on the panel: sage for up, red for down.
seriesHistory drawn as the sparkline, oldest first. Hold and drag it to scrub.
tintSparkline color. Defaults to the style's line.
expandedOptional binding to the expanded state, for driving it from outside.
styleTile, text, and chip colors. Defaults to .standard, a neutral glass tile; .block(_:) tints the glass with a color block and dark ink.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add LiveStat

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Live Stat" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All data and charts →

Build it yourself: SwiftUI animations guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

54 screens · 46 patterns · 48 flows · 12 templates · 31 Build Kit skills

Explore Pro