statbox
Statistic box for dashboards with the value, the change against a previous period, a sparkline, a goal meter and five styles, updated in real time
A box that shows one metric of a dashboard: visitors, page views, bounce rate, average time, sales... It reads the value from the model and re-renders on every change, so it works in real time (SET() the new value and the number counts to it). One component per box: put several of them in a grid.
The model is a Number (only the value) or an Object:
{
value: 1284, // {Number} the metric
previous: 1143, // {Number} optional, the value of the previous period: the change is computed from it
delta: 12.3, // {Number} optional, the change in percent; it wins over "previous"
trend: [820, 932, ...], // {Number[]} optional, values for the sparkline (2 or more, the last one is the current one)
target: 10000 // {Number} optional, a goal: shows a meter with value / target
}null,undefinedor a missingvalueshows theemptytext.- The change is shown with an arrow and a sign (
+12.3 %), not only with a colour. The colour says if the change is good or bad according togoodup. - The label is the content of the tag, so it can contain markup and
@(...)translations:<ui-component name="statbox" path="stats.visitors">@(Visitors)</ui-component>. - The numbers are formatted with
Intl.NumberFormatin the language of the page (<html lang>) or thelocaleoption. - The count animation, the meter transition and the live pulse are disabled when the user prefers reduced motion.
- With
clickthe box is a button: it is focusable and works withEnterandSpace.
Configuration:
label {String}the label when the content of the tag is empty (default:'')icon {String}Total.js icon of the label, example:ti ti-users(default:'')style {String}card,accent(a coloured bar on the left),soft(tinted background),solid(coloured background) orminimal(no box) (default:card)size {String}small,normalorlarge(a hero number of 48px) (default:normal)color {String}a hex colour of the box instead of the primary colour of the app, example:#6250D6(default:'')format {String}number,percent(the value is in percent,38.4is38.4 %),currencyorduration(the value is in seconds,185is3 m 05 s) (default:number)decimals {Number}the maximum count of decimals (default:0)compact {Boolean}values from 10,000 are shortened:12.9K,1.5M(default:true)currency {String}the currency code forformat:currency(default:EUR)locale {String}a language for the numbers, example:es-ES; empty is the language of the page (default:'')unit {String}a unit after the value, example:ms(default:'')period {String}a text next to the change, example:vs yesterday(default:'')live {String}a text with a pulsing dot that marks the box as live, example:Live; empty hides it (default:'')goodup {Boolean}a growing value is good (green); setfalsefor metrics where less is better, such as the bounce rate or the load time (default:true)animate {Boolean}the number counts from the previous value to the new one (default:true)empty {String}the text without a value (default:—)
Callbacks:
click {String}link to a globalfunction(value, component), executed when the user clicks the box or pressesEnter/Spaceon it;valueis the model
Runtime: jComponent v20, no dependencies.




