sparkline
Shows a number with a small trend line, colored by the first-to-last change by default.
Examples
Shows the close prices of the last 24 hourly K-lines.
javascript
function main() {
var r = exchange.GetRecords(PERIOD_H1)
if (!r || r.length < 24) return
var closes = r.slice(-24).map(function (b) { return b.Close })
LogStatus({type: "sparkline", title: "Last 24 hours", data: closes})
}
python
def main():
r = exchange.GetRecords(PERIOD_H1)
if not r or len(r) < 24:
return
closes = [b["Close"] for b in r[-24:]]
LogStatus({"type": "sparkline", "title": "Last 24 hours", "data": closes})
rust
fn main() {
let Ok(r) = exchange.GetRecords(None, PERIOD_H1, None) else { return };
if r.len() < 24 { return; }
let closes: Vec<String> = r[r.len() - 24..].iter().map(|b| b.Close.to_string()).collect();
LogStatus!(format!(
r#"{{"type": "sparkline", "title": "Last 24 hours", "data": [{}]}}"#,
closes.join(",")
));
}Attributes
| Name | Type | Description |
type | string | Required. Always |
data | numeric array | Required. At least 2 numbers; non-numeric items are ignored. |
value | number / string | The large value. Defaults to the last item of |
unit | string | Unit. |
format | object | Number format |
color | string | Line color, by default |
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
When the first and last items have the same sign, the change between them is shown as a percentage next to the value; it is hidden when the signs differ (for example a funding rate turning negative).