Reference
Chart
A chart drawn as vector graphics when the page is built: bars, lines, areas, a pie or a donut over a list of records.
Chart(kind: Enum, data: [Json], x: String, …)
Since 5.2.0
kind
bar
line
area
pie
donut
Example
Chart(kind: .bar, data: [
{ month: "Jan", web: 41, store: 22 },
{ month: "Feb", web: 48, store: 25 },
{ month: "Mar", web: 56, store: 24 },
{ month: "Apr", web: 61, store: 30 },
], x: "month", y: ["web", "store"], unit: "k").legend
A line over time
Chart(kind: .line, data: [
{ week: "W1", users: 120 }, { week: "W2", users: 180 }, { week: "W3", users: 260 }, { week: "W4", users: 310 },
], x: "week", y: "users", height: 220)
A donut with its labels
Chart(kind: .donut, data: [
{ channel: "Search", share: 52 }, { channel: "Direct", share: 31 }, { channel: "Social", share: 17 },
], x: "channel", y: "share", unit: "%").labels
Stacked, in your colours
Chart(kind: .bar, data: [
{ q: "Q1", new: 30, renewals: 52 }, { q: "Q2", new: 41, renewals: 55 },
], x: "q", y: ["new", "renewals"], colors: ["#0F766E", "#B45309"]).stacked.legend
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
kind: | one of its cases |
| What it draws (also written
|
data: | [Json] |
| The rows: a list of records ( |
x: | String | the row's first text field, or its number from 1 | The key of each row's label along the bottom (a pie's legend) |
y: | String or [String] | the row's first number field | The key of each row's value, or a list of keys for several series; a pie or donut uses the first |
colors: | [String] |
| The series' colours in order (a pie's: one a slice), repeated when there are more; one that is not a CSS colour is replaced by the default |
width: | Number |
| The drawing's width in its own units (its 11-unit text scales with it); on a page the SVG fills its box's width, so with |
height: | Number |
| The drawing's height in its own units; with |
ink: | String |
| The colour of its axis labels, value labels and legend text, a CSS colour |
grid: | String |
| The colour of its horizontal grid lines, a CSS colour |
legend: | Bool | true | Name the series above a bar, line or area chart (only with two or more), or list each slice with its value beside a pie; |
stacked: | Bool | false | Stack a bar chart's series in one bar a row; other kinds ignore it. Written as a flag, |
labels: | Bool | false | Write each bar's value above it (bars over 12 units tall) or each slice's percentage on it (slices over about 17°); lines and areas ignore it. Written as a flag, |
unit: | String | none | Written after each value on the axis and in a pie's legend: |
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
.line
.area
.pie
.donut
.legend
.stacked
.labels
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-chart, 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.