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

webstore0k20k40k60k80kJanFebMarApr

Example

wf

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

wf

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

wf

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

wf

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

Related:

Sparkline QrCode Stat

Props

Props of Chart
PropTypeUnsetMeaning

kind:

one of its cases

bar

What it draws (also written type:). Written as a flag, .bar, or by name, kind: .bar.

  • .bar (the default): Bars, one per row; grouped for several series, or stacked (the default)
  • .line: A line through the rows per series, a dot at each of up to 24 rows
  • .area: A line with the area under it filled at 18% opacity
  • .pie: Slices of a whole, one per row, from the first y key
  • .donut: A pie with a hole

data:

[Json]

[]: an empty grid

The rows: a list of records ({ month: "Jan", web: 41 }) or of numbers, known when the page is built (E109 on a page otherwise)

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]

#3B82F6, #10B981, #F59E0B, #EF4444, #8B5CF6, #06B6D4, #EC4899, #84CC16

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

600

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: it sets the shape

height:

Number

260

The drawing's height in its own units; with width: it sets the shape

ink:

String

#64748B

The colour of its axis labels, value labels and legend text, a CSS colour

grid:

String

#E2E8F0

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; legend: false leaves it out. Written as a flag, .legend, or legend: true.

stacked:

Bool

false

Stack a bar chart's series in one bar a row; other kinds ignore it. Written as a flag, .stacked, or stacked: true.

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, .labels, or labels: true.

unit:

String

none

Written after each value on the axis and in a pie's legend: ms, %

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.

These controls list the props' cases; the example below shows them written.