Reference
Sparkline
A tiny chart in a line of text — a line, or .bar — of a list of numbers, drawn as an SVG when the page is built.
Sparkline(_ data: [Number], bar: Bool, width: Number, height: Number, …)
Since 6.2.0
bar
Sign-ups this week
Errors by day
Example
Stack(gap: .sm) {
Row(gap: .sm, align: .center) {
Text("Sign-ups this week")
Sparkline([12, 18, 9, 24, 31, 27, 40], label: "Sign-ups this week")
}
Row(gap: .sm, align: .center) {
Text("Errors by day")
Sparkline([4, 2, 7, 1, 0, 3, 2], label: "Errors by day").bar
}
}
Its size and colour
Sparkline([3, 5, 4, 8, 6, 9], label: "Latency", width: 160, height: 32, color: "#0F766E")
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
data | [Number] (positional) | — | The numbers, a list, drawn as an SVG when the page is built, so they must be known then ( |
bar: | Bool | false | Bars from zero rather than a line. Written as a flag, |
width: | Number |
| Its width in px; 0 or less is the default |
height: | Number |
| Its height in px; 0 or less is the default |
color: | String | the text's colour | The line's or the bars' colour, a CSS colour ( |
label: | String |
| What it shows, as the picture's accessible name ( |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
.bar
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Renders with the class wf-sparkline, stable across releases, so a stylesheet may target it.
Codes this can raise
These controls list the props' cases; the example below shows them written.