[data-reveal]{opacity:1!important;transform:none!important}
KPI card
Components

KPI card

One headline figure with its variation versus the comparison period and an optional sparkline.

KpiCard headlines one metric followed over a period: a large formatted value, a colored up / down delta badge with its comparison caption, and an optional inline sparkline. The stat variant is the tighter DMS look, with a mono uppercase label and a bare icon.

KPI cardKpiCard
Connecting to the DMS preview…
ConnectingDMS 0.9.511 options set

Usage

src/pages/sales.ts
import { KpiCard } from "@antelopejs/interface-dms/base/kpi-card";

static revenue = KpiCard({
  title: "$shop.sales.revenue",
  icon: "i-ph-currency-eur",
  fetchUrl: "/api/sales/revenue",
  periodScope: "sales",
  valueFormat: "currency",
  currencyCode: "EUR",
  showDelta: true,
  showSparkline: true,
});

The route answers the value, its variation and the sparkline points:

src/pages/sales.ts
@Get("revenue")
revenue() {
  return { value: 48200, delta: 12.4, previousValue: 42900, sparkline: [31, 34, 33, 38, 41, 39, 44, 48] };
}

Options

Options of the KPI card block
OptionTypeDefaultDescription
title*Contentstring–Card heading.
descriptionContentstring–Secondary line under the value.
compareLabelContentstring–
iconAppearancestring–The icon shown on the card.
variantAppearance"default" | "stat"–Stat draws the card in a compact style.
valueFormatAppearance"number" | "currency" | "percent" | "compact"–
currencyCodeAppearancestring–The currency, as a three-letter code such as EUR, when the value is an amount.
showDeltaAppearanceboolean–
showSparklineAppearanceboolean–
sparklineAccentAppearancestring–
invertBehaviorboolean–Treat a falling value as the good outcome.

valuePrecision is available in code (Value precision).

Recipes

A metric where down is good

Set invert: true for errors, churn or latency: a falling value then reads green.

A static card

Pass staticValue, staticDelta and staticSparkline instead of fetchUrl for a fixture or a demo.

Pitfalls

  • delta is a change in percent (12.5), not a ratio (0.125).
  • For several figures read at a glance, without a period, use a StatGroup: its cards layout draws the same compact card as KpiCard({ variant: "stat" }).

Next steps

Chart card

The same headline with the series behind it.

Period selector

Drive the card's period.