Stat Card

Free

KPI 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 demo

More examples

A KPI row on one scale, with a cost that should fall

example.htmlAngular
<!-- 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
<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
<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

NameTypeDefaultDescription
titlestring''Card title / metric label.
valuestring | number''Primary metric value — string or number, displayed as-is or formatted.
prefixstring''Optional prefix rendered before the value (e.g. "$", "€").
suffixstring''Optional suffix rendered after the value (e.g. "K", "%", "ms").
descriptionstring''Short helper text beneath the title (e.g. "Last 30 days").
trendStatCardTrend'neutral'Direction of change.
trendValuenumber | nullnullAbsolute delta value shown alongside the trend icon.
trendPercentnumber | nullnullPercentage change shown in the trend chip.
trendLabelstring''Comparison context label (e.g. "vs last month").
trendPolarityStatCardTrendPolarity'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.
sparklineDomainreadonly [number, number] | nullnull`[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.
updatedAtstring''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.
staleAfterMinutesnumber60How many minutes before the figure is called out as possibly stale.
sourcestring''Where the figure came from — a warehouse, a job, a service.
layoutStatCardLayout'default'Card layout mode.
iconstring''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.
sparklineSparkPoint[][]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.
loadingbooleanfalseShow skeleton loading shimmer instead of content.
errorSvDataError | string | nullnullThe 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`.
linkLabelstring''Label for the bottom "view more" link. Empty string hides the link.
customClassstring''Additional CSS classes merged on the root card element.
localestringsvLocale()BCP 47 locale for dates and numbers.

Outputs

EventPayload typeDescription
linkClickvoidEmitted when the "view more" link is clicked.
retryvoidThe 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

NameTypeDefaultDescription
titlestring''Card title / metric label.
valuestring | number''Primary metric value — string or number, displayed as-is or formatted.
prefixstring''Optional prefix rendered before the value (e.g. "$", "€").
suffixstring''Optional suffix rendered after the value (e.g. "K", "%", "ms").
descriptionstring''Short helper text beneath the title (e.g. "Last 30 days").
trendStatCardTrend'neutral'Direction of change.
trendValuenumber | nullnullAbsolute delta value shown alongside the trend icon.
trendPercentnumber | nullnullPercentage change shown in the trend chip.
trendLabelstring''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.
trendPolarityStatCardTrendPolarity'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.
sparklineDomainreadonly [number, number] | nullnull`[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.
updatedAtstring''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.
staleAfterMinutesnumber60How many minutes before the figure is called out as possibly stale.
sourcestring''Where the figure came from — a warehouse, a job, a service.
variantStatCardVariant'default'Color variant — drives icon background, accent line and trend colors.
layoutStatCardLayout'default'Card layout mode.
iconstring''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.
sparklineSparkPoint[][]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.
loadingbooleanfalseShow skeleton loading shimmer instead of content.
errorSvDataError | string | nullnullThe 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`.
linkLabelstring''Label for the bottom "view more" link. Empty string hides the link.
clickablebooleanfalseMake the whole card interactive (clickable + keyboard focusable). When `true` the root becomes a `role="button"` that emits `cardClick` on click, Enter or Space.
customClassstring''Additional CSS classes merged on the root card element.
localestringsvLocale()BCP 47 locale for dates and numbers.

Outputs

EventPayload typeDescription
cardClickvoidEmitted when an interactive card is activated by click, Enter or Space.
linkClickvoidEmitted when the "view more" link is clicked.
retryvoidThe 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.

Loads giscus.app and GitHub — nothing is fetched until you click.