import { Component } from '@angular/core';
import { WrStatistic, WrStatisticCountdown, WrStatisticGroup } from 'ngwr/statistic';
@Component({ imports: [WrStatistic, WrStatisticCountdown, WrStatisticGroup] })
export class MyComponent {}Statistic
A key number with a label and an optional change.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Basic
<wr-statistic label="Active users" [value]="12345" />
<wr-statistic label="Revenue" [value]="9512" prefix="$" [delta]="12.4" />Dashboard grid
<wr-statistic-group> reflows to its own width (drag the corner): min sets the narrowest column, columns the most per row.
<wr-statistic-group [columns]="4" min="11rem">
<wr-statistic label="Active users" [value]="12345" />
<wr-statistic label="Revenue" [value]="9512" prefix="$" [delta]="12.4" />
<wr-statistic label="Churn" [value]="1.8" [precision]="1" suffix="%" [delta]="-0.4" />
<wr-statistic label="Sessions" [value]="48210" />
</wr-statistic-group>Count up
A new number counts up from the old one; [animate]='false' turns it off.
<wr-statistic label="Revenue" prefix="$" [value]="revenue()" [precision]="2" [delta]="delta()" />
<wr-statistic label="Sessions" [value]="sessions()" />
protected readonly revenue = signal(9512.4);
protected readonly sessions = signal(48210);
protected readonly delta = signal(12.4);
constructor() {
const id = setInterval(() => {
this.revenue.set(Math.round(Math.random() * 5_000_00) / 100);
this.sessions.set(Math.floor(Math.random() * 90_000));
this.delta.set(Math.round((Math.random() * 40 - 20) * 10) / 10);
}, 2000);
inject(DestroyRef).onDestroy(() => clearInterval(id));
}Countdown
<wr-statistic-countdown> counts down to target; format takes D, H, m, s (doubled to pad) and SSS. A unit the format leaves out is carried into the largest one it shows, so HH:mm:ss reads 73:00:00 three days out.
<wr-statistic-countdown
label="Launch in"
[target]="launchDate"
format="D days HH:mm:ss"
(countdownEnd)="onLive()"
/>
protected readonly launchDate = new Date(Date.now() + 1000 * 60 * 60 * 36);API
| Name | Description | Type | Default |
|---|---|---|---|
<wr-statistic> | KPI card. | component | — |
label | Label above the value. | string | '' |
value | Main number or string shown. | number | string | null | null |
prefix | Leading glyph or symbol. | string | '' |
suffix | Trailing glyph or unit. | string | '' |
precision | Fixed decimals for numeric values. | number | 0 |
animate | Count up to a new numeric value (off for strings / reduced motion). | boolean | true |
duration | Count-up duration in ms. | number | 700 |
delta | Change vs previous period. | number | null | null |
deltaSuffix | Unit appended to the delta. Falls back to the statistic.deltaSuffix catalog key. | string | null | null |
<wr-statistic-group> | Grid that reflows to its own width. | component | — |
min | Minimum column width before the grid reflows to fewer columns. | string | '12rem' |
columns | Cap on columns for a wide container (0 = uncapped). | number | 0 |
<wr-statistic-countdown> | Live countdown variant. | component | — |
targetrequired | Date or timestamp to count down to. | Date | string | number | — |
label | Label above the value. | string | '' |
format | Format string for the remaining time. | string | 'HH:mm:ss' |
endText | Text shown once it reaches zero. | string | null | null |
tickMs | Tick interval in milliseconds. | number | 1000 |
(countdownEnd) | Emits once when the target time is reached. | void | — |
CSS variables
Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/statistic's own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-statistic-affix-font-size | var(--wr-text-lg) | .wr-statistic |
--wr-statistic-affix-font-weight | var(--wr-font-weight-medium) | .wr-statistic |
--wr-statistic-delta-font-size | var(--wr-text-xs) | .wr-statistic |
--wr-statistic-delta-font-weight | var(--wr-font-weight-semibold) | .wr-statistic |
--wr-statistic-delta-gap | var(--wr-space-xs) | .wr-statistic |
--wr-statistic-font-family | var(--wr-font-family-base) | .wr-statistic |
--wr-statistic-gap | var(--wr-space-xs) | .wr-statistic |
--wr-statistic-group-font-family | var(--wr-font-family-base) | .wr-statistic-group |
--wr-statistic-group-gap | var(--wr-space-xl) | .wr-statistic-group +1 variant override |
--wr-statistic-label-font-size | var(--wr-text-sm) | .wr-statistic |
--wr-statistic-label-line-height | var(--wr-leading-normal) | .wr-statistic |
--wr-statistic-value-font-size | var(--wr-text-3xl) | .wr-statistic |
--wr-statistic-value-font-weight | var(--wr-font-weight-semibold) | .wr-statistic |
--wr-statistic-value-gap | var(--wr-space-xs) | .wr-statistic |
--wr-statistic-value-letter-spacing | var(--wr-tracking-tight) | .wr-statistic |
--wr-statistic-value-line-height | var(--wr-leading-tight) | .wr-statistic |
Dependencies
| Built on | Counter |
|---|
See also
Component SparklineA small trend line with no axes, to sit beside a number.Component CardA surface that groups related content.Component DescriptionsA read-only list of labels and their values.Component GaugeA read-only semicircle dial for a single value.Pipe wrNumberFormat a number, percent or price in the app locale.Component CounterAn animated number: rolling digits or an eased count.