Stat
A number with a delta and a sparkline.
On this page
Examples
Typed numbers
Value and Delta are numbers, formatted with Format and Culture; the sign of the delta picks its color unless DeltaDirection is set. Write a number as an expression (Value="@_revenue"): a bare attribute value is text. A nullable value shows a dash.
Monthly revenuevs last month
$148,900
+14.2%Error rateA drop is good news
1.2%
-0.4 ptOpen ticketsNo value shows a dash
—
Razor
<div class="grid w-full gap-4 md:grid-cols-2">
<KlyStat Title="Monthly revenue" Value="@_revenue" Format="C0" Culture="@_en" Delta="@_change" DeltaFormat="+0.0;-0.0" DeltaUnit="%"
Trend="@_trend" Caption="vs last month" Surface="KlySurface.Bordered" />
<KlyStat Title="Error rate" Value="@_errors" Format="P1" Delta="@(-0.4)" DeltaFormat="+0.0;-0.0" DeltaUnit=" pt"
DeltaDirection="KlyDeltaDirection.Up" Caption="A drop is good news" Surface="KlySurface.Bordered" />
<KlyStat Title="Open tickets" Value="@_missing" Caption="No value shows a dash" Surface="KlySurface.Bordered" />
<KlyStat Title="Loading" Value="@_revenue" Loading Surface="KlySurface.Bordered" />
</div>
@code {
private readonly System.Globalization.CultureInfo _en = System.Globalization.CultureInfo.GetCultureInfo("en-US");
private readonly decimal _revenue = 148_900m;
private readonly decimal _change = 14.2m;
private readonly double _errors = 0.012;
private readonly int? _missing = null;
private readonly double[] _trend = [102, 98, 115, 110, 132, 128, 149];
}API
KlyStat<TValue>
A highlighted number with a title, unit, delta badge, sparkline and caption. is a built-in number type ( SByte to UInt64 , Single , Double , Decimal ) or its nullable form, which shows a dash when it has no value: Blazor infers it from Value or Delta (write the number as an expression, Value="@amount" ). Another type throws an InvalidOperationException that lists the supported ones.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Caption |
string |
A line of smaller text under the value. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Culture |
CultureInfo |
The culture that formats the numbers. Defaults to the format culture of the locale in effect. | |
Delta |
TValue |
The change shown as a badge beside the value. Its direction comes from its sign unless DeltaDirection is set. With a nullable type, no value means no badge; with a plain number type the default, zero, shows a flat badge. | |
DeltaDirection |
KlyDelta |
The direction of Delta , which only chooses the color of its badge: Up (success), Down (error) or Flat (neutral). When null , it comes from the sign of Delta . Set it for a change where a drop is good news (a cost, an error rate). Values: Up, Down, Flat. |
|
DeltaFormat |
string |
"+#,0.##;-#,0.##;0" |
The format string of Delta ( "+#,0.##;-#,0.##;0" by default, which always shows the sign). |
DeltaUnit |
string |
Text written after Delta , such as "%" . | |
Format |
string |
"#,0.##" |
The .NET numeric format string of Value ( "#,0.##" by default; "C0" shows the currency of Culture , "P1" a percentage). |
Loading |
bool |
false |
Shows a skeleton placeholder instead of the content. |
Surface |
KlySurface? |
The surface treatment. Muted when not set. Values: Plain, Muted, Bordered, Elevated. |
|
Title |
string |
The label of the value. | |
Trend |
IReadOnlyList |
The series of the sparkline, drawn from two points or more. | |
Ui |
StatUi |
Per-instance class overrides of the slots of the stat, see StatUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Unit |
string |
The unit shown beside the value, as text. | |
Value |
TValue |
The value, formatted with Format and Culture . A dash when it is a nullable type with no value, or not finite. |
Ui slots
Ui takes a StatUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyStat`1 , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlyStat`1 , after the theme and the app configuration. |
Row |
Classes merged into the row slot of KlyStat`1 , after the theme and the app configuration. |
ValueGroup |
Classes merged into the valueGroup slot of KlyStat`1 , after the theme and the app configuration. |
Value |
Classes merged into the value slot of KlyStat`1 , after the theme and the app configuration. |
Unit |
Classes merged into the unit slot of KlyStat`1 , after the theme and the app configuration. |
Delta |
Classes merged into the delta slot of KlyStat`1 , after the theme and the app configuration. |
Sparkline |
Classes merged into the sparkline slot of KlyStat`1 , after the theme and the app configuration. |
Caption |
Classes merged into the caption slot of KlyStat`1 , after the theme and the app configuration. |
Skeleton |
Classes merged into the skeleton slot of KlyStat`1 , after the theme and the app configuration. |