# Stat card

A headline number that counts up, a trend pill and a chart in one card.

Section: Charts / Figures
Page: https://ui.heyramzi.com/components/stat-card
Import path: `@heyramzi/ui/charts`

## Import

```ts
import { StatCard } from "@heyramzi/ui/charts";
```

## Usage

```svelte
<StatCard
  label="Revenue"
  value={48200}
  delta={12.4}
  caption="vs last month"
  variant="area"
  data={[{ m: "Jan", v: 3200 }]}
  xKey="m"
  yKey="v"
/>
```

## Demo

```svelte
<script lang="ts">
	import { StatCard } from "@heyramzi/ui/charts";

	const data = [
		{ m: "Jan", v: 3200 },
		{ m: "Feb", v: 4100 },
		{ m: "Mar", v: 3800 },
		{ m: "Apr", v: 5300 },
		{ m: "May", v: 6100 },
		{ m: "Jun", v: 7200 },
	];
</script>

<div class="@container w-full max-w-[44rem]">
	<div class="grid gap-4 @xl:grid-cols-3">
		<StatCard
			label="Revenue"
			value={48200}
			delta={12.4}
			caption="vs last month"
			variant="area"
			{data}
			xKey="m"
			yKey="v"
		/>
		<StatCard
			label="Orders"
			value={1284}
			delta={-3.1}
			caption="vs last month"
			variant="bar"
			{data}
			xKey="m"
			yKey="v"
			color="var(--chart-3)"
		/>
		<StatCard
			label="Uptime"
			value={99}
			delta={0.2}
			caption="30 days"
			variant="gauge"
			gaugeValue={99}
			gaugeLabel="Uptime"
		/>
	</div>
</div>
```

## API

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `data` | `TData[]` | `[]` | Series for the line/area/bar variants. Unused by the gauge variant. |
| `xKey` | `keyof TData & string` |  |  |
| `yKey` | `keyof TData & string` |  |  |
| `variant` | `"line"` \| `"area"` \| `"bar"` \| `"gauge"` | `"area"` | Chart kind. "gauge" puts a radial gauge to the right of the figure. |
| `gaugeValue` | `number` |  | Arc fill 0-100 for variant="gauge". Falls back to `value` when numeric. |
| `gaugeLabel` | `string` |  | Label under the gauge percentage. |
| `label` | `string` |  | Metric name shown top-left. Omit (or set `figureOnly`) for a bare chart. |
| `value` | `number` |  | Headline number; counts up on mount. |
| `delta` | `number` |  | Percentage change. Its sign drives the trend color/arrow unless `trend` is set. |
| `trend` | `"up"` \| `"down"` \| `"neutral"` |  | Force the trend direction independent of `delta`'s sign. |
| `caption` | `string` |  | Caption under the value, e.g. "Avg" or "vs last month". |
| `figureOnly` | `boolean` | `false` | Render only the edge-to-edge chart, no header/value/caption. |
| `color` | `string` | `"var(--chart-series-1)"` |  |
| `height` | `number` | `150` | Chart height in px. |
| `smooth` | `boolean` | `true` |  |
| `edgeFade` | `boolean \| number` | `true` | Softens the left and right ends of the line and the area fill instead of cutting them off at the card edge. |
| `formatValue` | `(v: number) => string` | `(v) => v.toLocaleString()` | Format for the headline value. |
| `formatX` | `(v: unknown) => string` | `(v) => String(v)` | Format for the x value shown as the tooltip header (e.g. a date/period). |
| `icon` | `Snippet` |  | Leading icon next to the label. |
| `class` | `string` |  |  |
