BarChart data
Bars that grow one after another with a spring; each has its number counting up on top and a label under it.
Props#
| Prop | Type | Default | Notes |
|---|---|---|---|
| items* | list of object | ||
| max | number | 100 | the value a full-height bar stands for |
| h | number (160 to 1200) | 460 | |
| w | number (10 to 300) | 84 | one bar's width |
| color | color | "accent" | |
| each | number (0 to 1) | 0.09 | |
| bounce | number (0 to 0.9) | 0.35 |
* required. Every node also takes the common props: id, motion, start, place, scale, rotate, opacity, w, h. A colour is a palette name, never a value.
Parts#
Named parts can be restyled from outside without making a new component: "parts": { "root": { … } }.
| Part | Is a |
|---|---|
| root | box |
| bar | shape |
| label | text |
Example#
{
"el": "BarChart",
"items": [{"label": "Mon", "value": 30}, {"label": "Tue", "value": 55}, {"label": "Wed", "value": 90}]
}How it is made#
This component is plain data. Its whole definition is the tree below: copy it into a scene's components list under a new name to make your own version. See Custom components.
{
"el": "box",
"dir": "row",
"gap": 26,
"align": "end",
"h": "$h",
"motion": [{"do": "stagger", "each": "$each"}],
"children": [
{
"$each": "$items",
"as": "d",
"node": {
"el": "box",
"gap": 12,
"align": "center",
"justify": "end",
"h": "fill",
"children": [
{
"el": "text",
"text": "0",
"size": 34,
"weight": 700,
"motion": [
{"do": "enter", "from": "fade", "delay": 0.1},
{"do": "count", "to": "$d.value", "curve": {"ease": "outExpo", "duration": 0.9}}
]
},
{
"el": "shape",
"id": "bar",
"kind": "rect",
"w": "$w",
"h": "=d.value/max*(h-130)",
"radius": 16,
"fill": "$color",
"origin": "bottom",
"motion": [
{
"do": "enter",
"from": {"scaleY": 0},
"curve": {"spring": {"bounce": "$bounce", "duration": 0.7}}
}
]
},
{
"el": "text",
"id": "label",
"text": "$d.label",
"size": 34,
"weight": 600,
"color": "muted"
}
]
}
}
]
}