kpi
Shows one prominent number with optional unit, change and hint, for equity, returns or the last price.
Examples
A KPI card shows the last price and its change from the open.
javascript
function main() {
var ticker = exchange.GetTicker()
if (!ticker) return
var change = ticker.Open > 0 ? (ticker.Last / ticker.Open - 1) * 100 : 0
LogStatus({type: "kpi", title: "Last price", value: ticker.Last,
delta: change, hint: "vs. open"})
}
python
def main():
ticker = exchange.GetTicker()
if not ticker:
return
change = (ticker["Last"] / ticker["Open"] - 1) * 100 if ticker["Open"] > 0 else 0
LogStatus({"type": "kpi", "title": "Last price", "value": ticker["Last"],
"delta": change, "hint": "vs. open"})
rust
fn main() {
let Ok(t) = exchange.GetTicker(None) else { return };
let change = if t.Open > 0.0 { (t.Last / t.Open - 1.0) * 100.0 } else { 0.0 };
LogStatus!(format!(
r#"{{"type": "kpi", "title": "Last price", "value": {}, "delta": {}, "hint": "vs. open"}}"#,
t.Last, change
));
}Attributes
| Name | Type | Description |
type | string | Required. Always |
value | number / string | Required. The value: numbers are formatted with |
unit | string | Unit shown after the value. |
delta | number | Change: positive values show the up color with ▲, negative ones the down color with ▼, 2 decimals. |
deltaUnit | string | Unit of |
format | object | Number format |
color | string | Color: |
hint | string | Note shown under the value. |
title | string | Title shown at the top left of the component. |
id | string | Stable identifier. Set it when the number or order of components changes, so refreshes do not rebuild the component. |
span | number | Number of columns it spans in the enclosing |
See Also
Remarks
delta is the change itself, not a ratio: write 3.2 for a 3.2% rise. When value uses format.percent, pass a ratio (0.032).