Stat Card
FreeKPI metric cards with sparklines, trend chips and four layout variants.
</>sv-stat-card kpimetricdashboard
Complexity tier: Primitive Presents a value: held to semantic markup and contrast, laid out with logical properties so it mirrors under right-to-left, and with what it does on paper decided.
import { SvStatCardComponent } from '@styloviz/stat-card';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
A KPI row on one scale, with a cost that should fall
example.htmlAngular
3 lines
<!-- one domain for the row: svSharedDomain(cards.map(c => c.series)) --> <sv-stat-card title="Revenue" [value]="1250000" trend="up" [trendPercent]="8.2" trendLabel="vs last month" [sparkline]="revenue" [sparklineDomain]="rowDomain" /> <sv-stat-card title="Infra cost" [value]="48200" trend="up" [trendPercent]="12" trendLabel="vs last month" trendPolarity="down-is-good" [sparkline]="cost" [sparklineDomain]="rowDomain" />
With sparkline & link
example.htmlAngular
7 lines
<sv-stat-card title="Active users" [value]="12840" [trendPercent]="-3.2" [sparkline]="series" linkLabel="View report" (linkClick)="open()" />
Clickable card, keyboard accessible (Pro)
example.htmlAngular
6 lines
<sv-stat-card-pro title="Open tickets" [value]="42" variant="warning" [clickable]="true" (cardClick)="drillDown()" />
When to use
Surfacing a single headline metric with its trend at the top of a dashboard. You want an inline sparkline and a semantic up/down trend chip. For many metrics at once, arrange several cards in a Widget Grid.
Async states
- loading
- error
- retry
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | '' | Card title / metric label. |
| value | string | number | '' | Primary metric value — string or number, displayed as-is or formatted. |
| prefix | string | '' | Optional prefix rendered before the value (e.g. "$", "€"). |
| suffix | string | '' | Optional suffix rendered after the value (e.g. "K", "%", "ms"). |
| description | string | '' | Short helper text beneath the title (e.g. "Last 30 days"). |
| trend | StatCardTrend | 'neutral' | Direction of change. |
| trendValue | number | null | null | Absolute delta value shown alongside the trend icon. |
| trendPercent | number | null | null | Percentage change shown in the trend chip. |
| trendLabel | string | '' | Comparison context label (e.g. "vs last month"). |
| trendPolarity | StatCardTrendPolarity | 'up-is-good' | Which direction is good news — see StatCardTrendPolarity. `'up-is-good'` paints a rise green and a fall red; `'down-is-good'` swaps them, for a churn or cost KPI; `'neutral'` paints any change grey. |
| sparklineDomain | readonly [number, number] | null | null | `[min, max]` for the inline sparkline, shared across a KPI row. Unset, each card scales its line to itself, and two cards rising 2% and 900% draw the same shape side by side. Compute one range with `svSharedDomain()` from `@styloviz/sparkline` over every card's series and bind it to all of them. An sr-only note says which kind of scale the line is on. |
| updatedAt | string | '' | When this figure was last refreshed, as `YYYY-MM-DD` or an ISO timestamp. Renders an "Updated … ago" line under the figure, marked stale past `staleAfterMinutes`, because a cached KPI looks identical to a live one. |
| staleAfterMinutes | number | 60 | How many minutes before the figure is called out as possibly stale. |
| source | string | '' | Where the figure came from — a warehouse, a job, a service. |
| layout | StatCardLayout | 'default' | Card layout mode. |
| icon | string | '' | Name of an icon in `@styloviz/icons`, e.g. `'trending-up'`. A library glyph is always drawn on a 24-unit box, so there is no viewBox to pass. |
| sparkline | SparkPoint[] | [] | Array of data points for the inline sparkline. Values should be on a consistent numeric scale; the component normalises them internally. Empty array hides the sparkline. |
| loading | boolean | false | Show skeleton loading shimmer instead of content. |
| error | SvDataError | string | null | null | The figure could not be loaded. Rendered in place of the metric, because a card that keeps showing a stale number after a failed refresh is worse than one that admits it: the reader has no way to tell the two apart. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. |
| linkLabel | string | '' | Label for the bottom "view more" link. Empty string hides the link. |
| customClass | string | '' | Additional CSS classes merged on the root card element. |
| locale | string | svLocale() | BCP 47 locale for dates and numbers. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| linkClick | void | Emitted when the "view more" link is clicked. |
| retry | void | The host should re-run the failed load. |
<sv-stat-card-pro>
Also in this family — SvStatCardProComponent from @styloviz-pro/stat-card.
Async states
- loading
- error
- retry
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | '' | Card title / metric label. |
| value | string | number | '' | Primary metric value — string or number, displayed as-is or formatted. |
| prefix | string | '' | Optional prefix rendered before the value (e.g. "$", "€"). |
| suffix | string | '' | Optional suffix rendered after the value (e.g. "K", "%", "ms"). |
| description | string | '' | Short helper text beneath the title (e.g. "Last 30 days"). |
| trend | StatCardTrend | 'neutral' | Direction of change. |
| trendValue | number | null | null | Absolute delta value shown alongside the trend icon. |
| trendPercent | number | null | null | Percentage change shown in the trend chip. |
| trendLabel | string | '' | What the trend is measured AGAINST — "vs last month", "vs Q3". A KPI without its comparison period is a decoration. "+12%" against last week, last month and last year are three different claims, and the reader has no way to pick between them, so supply it in any real dashboard. Where it is missing, the trend's accessible name says so rather than reading a bare percentage as though it meant something. |
| trendPolarity | StatCardTrendPolarity | 'up-is-good' | Which direction is good news — see StatCardTrendPolarity. `'up-is-good'` paints a rise green and a fall red; `'down-is-good'` swaps them, for a churn or cost KPI; `'neutral'` paints any change grey. |
| sparklineDomain | readonly [number, number] | null | null | `[min, max]` for the inline sparkline, shared across a KPI row. Unset, each card scales its line to itself, and two cards rising 2% and 900% draw the same shape side by side. Compute one range with `svSharedDomain()` from `@styloviz/sparkline` over every card's series and bind it to all of them. An sr-only note says which kind of scale the line is on. |
| updatedAt | string | '' | When this figure was last refreshed, as `YYYY-MM-DD` or an ISO timestamp. Renders an "Updated … ago" line under the figure, marked stale past `staleAfterMinutes`, because a cached KPI looks identical to a live one. |
| staleAfterMinutes | number | 60 | How many minutes before the figure is called out as possibly stale. |
| source | string | '' | Where the figure came from — a warehouse, a job, a service. |
| variant | StatCardVariant | 'default' | Color variant — drives icon background, accent line and trend colors. |
| layout | StatCardLayout | 'default' | Card layout mode. |
| icon | string | '' | Name of an icon in `@styloviz/icons`, e.g. `'trending-up'`. A library glyph is always drawn on a 24-unit box, so there is no viewBox to pass. |
| sparkline | SparkPoint[] | [] | Array of data points for the inline sparkline. Values should be on a consistent numeric scale; the component normalises them internally. Empty array hides the sparkline. |
| loading | boolean | false | Show skeleton loading shimmer instead of content. |
| error | SvDataError | string | null | null | The figure could not be loaded. Rendered in place of the metric, because a card that keeps showing a stale number after a failed refresh is worse than one that admits it: the reader has no way to tell the two apart. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. |
| linkLabel | string | '' | Label for the bottom "view more" link. Empty string hides the link. |
| clickable | boolean | false | Make the whole card interactive (clickable + keyboard focusable). When `true` the root becomes a `role="button"` that emits `cardClick` on click, Enter or Space. |
| customClass | string | '' | Additional CSS classes merged on the root card element. |
| locale | string | svLocale() | BCP 47 locale for dates and numbers. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| cardClick | void | Emitted when an interactive card is activated by click, Enter or Space. |
| linkClick | void | Emitted when the "view more" link is clicked. |
| retry | void | The host should re-run the failed load. |
Customization & theming
`trendPolarity` says which direction is good news: `'down-is-good'` for churn, cost or latency paints a fall green and a rise red; `'neutral'` paints any change grey. The arrow and the spoken direction follow `trend` regardless. Numbers abbreviate from 1,000 up with `svFormatCompact` (`@styloviz/core`) in the locale's compact notation — "2.5M", "-2.5M", "2,5 Mio.", "1.2万" — identically in the free, Pro and Spotlight cards; pass a string to opt out. Bind one `sparklineDomain` (from `svSharedDomain()` in `@styloviz/sparkline`) to every card in a KPI row so the lines are drawn on one scale. Four layouts plus optional inline sparkline. Trend chip colors follow the semantic palette. Format values with your own pipe before binding. Set `clickable` on `sv-stat-card-pro` to make the whole card an interactive button that emits `cardClick`.
Best practices
Do: Pass a number to get locale-aware compact notation; pass a pre-formatted string only to opt out. Do: Set `trend` (and `trendPolarity` when down is good) — it drives the chip colour and the spoken direction. Don't: Don't pack more than one metric into a single card — split them.
Accessibility
Beside an inline sparkline an sr-only note says whether the line shares a scale with the row ("on a scale shared with the other cards, 0 to 100") or is scaled to the card alone — the line itself is hidden from assistive tech. Values and trends are real text, not images. A `clickable` card (Pro) is a button named by its content — title, value, trend — not by its title alone, which hid the value from a screen reader. Sufficient contrast across variants and dark mode. A `clickable` card (Pro) exposes `role="button"`, is focusable, and activates on Enter/Space. Decorative icons and sparklines are hidden from assistive tech; loading state sets `aria-busy`.
Feedback on Stat Card
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.