BarChart
The built-in barchart tag — a bar chart from JSON data and series. Usage, the data/series shape, and a live example.
A bar chart for comparing values across categories. Give it the rows in data (a JSON array
of objects) and the bars in series (a JSON array of {name, color}), with dataKey naming the
category axis. Several series put their bars side by side in each category group, and hovering a
group opens a tooltip with its values.
Use it as {% barchart %} in Markdown, or call it from Python logic (loops,
snippets) via component('charts', 'BarChart', …).
The charts need @mantine/charts installed. Chart tags resolve against the charts
component library, which the packaged theme
declares, over @mantine/charts. A site
scaffolded by vark new installs the package, so the tags work as written. Without the
package the chart renders nothing, and the build warns and names the package to install.
Charts are drawn in the browser (they measure their live container), so they are not part of the pre-rendered HTML and do not appear with JavaScript turned off.
The charts need @mantine/charts installed. Chart tags resolve against the charts
component library, which the packaged theme
declares, over @mantine/charts. A site
scaffolded by vark new installs the package, so the tags work as written. Without the
package the chart renders nothing, and the build warns and names the package to install.
Charts are drawn in the browser (they measure their live container), so they are not part of the pre-rendered HTML and do not appear with JavaScript turned off.
Python calls pass data and series as Python lists; the Markdown tag accepts JSON strings.
A basic bar chart
{% barchart h=260 dataKey='product' withLegend=true data='[
{"product":"Free","Q1":40,"Q2":55},
{"product":"Pro","Q1":80,"Q2":120},
{"product":"Team","Q1":30,"Q2":48}
]' series='[{"name":"Q1","color":"violet.6"},{"name":"Q2","color":"blue.6"}]' %}
component('charts', 'BarChart', h=260, dataKey='product', withLegend=True,
data=[
{'product': 'Free', 'Q1': 40, 'Q2': 55},
{'product': 'Pro', 'Q1': 80, 'Q2': 120},
{'product': 'Team', 'Q1': 30, 'Q2': 48},
],
series=[
{'name': 'Q1', 'color': 'violet.6'},
{'name': 'Q2', 'color': 'blue.6'},
])
Attributes
| Attribute | Valid values | Description |
|---|---|---|
data |
JSON array of row objects | The chart rows. Malformed JSON warns during the build and draws an empty chart. |
series |
JSON array of {name, color} |
One bar series per entry. name is the row field to plot; color is a theme color with a shade (violet.6) or any CSS color. |
dataKey |
string | The row field used for the category axis. |
h |
integer (px, default 300) |
Chart height. |
unit |
string | Unit appended to the value-axis ticks and the tooltip values. |
withLegend |
bool (true / false, default false) |
Show the legend. |
CSS Selectors
Target the rendered element through its island marker —
[data-aardvark-island="BarChart"] (or the more specific
[data-aardvark-lib="charts"][data-aardvark-island="BarChart"] when several
libraries share the page) — or through the Mantine Styles API classes
(.mantine-BarChart-root and its inner parts):
/* Every rendered BarChart carries this island marker */
[data-aardvark-island="BarChart"] { }
/* Scope by library + island when you have several libraries in play */
[data-aardvark-lib="charts"][data-aardvark-island="BarChart"] { }
/* Mantine Styles API class on the root element */
.mantine-BarChart-root { }
.mantine-BarChart-container { }
.mantine-BarChart-axis { }
.mantine-BarChart-bar { }
Injecting Attributes
attr={…} forwards raw HTML attributes — including event handlers — straight onto the rendered element, so you can wire DOM behavior the tag does not expose. The handler can be a full multi-line script, not just one expression — this one logs the value to the console and shows it in an alert:
{% barchart h=260 dataKey='product' withLegend=true data='[
{"product":"Free","Q1":40,"Q2":55},
{"product":"Pro","Q1":80,"Q2":120}
]' series='[{"name":"Q1","color":"violet.6"},{"name":"Q2","color":"blue.6"}]' attr={'onclick': '''
const value = this.innerText;
console.log('attr demo value:', value);
alert(value);
'''} %}
component('charts', 'BarChart', h=260, dataKey='product', withLegend=True,
data=[
{'product': 'Free', 'Q1': 40, 'Q2': 55},
{'product': 'Pro', 'Q1': 80, 'Q2': 120},
],
series=[
{'name': 'Q1', 'color': 'violet.6'},
{'name': 'Q2', 'color': 'blue.6'},
],
attr={'onclick': '''
const value = this.innerText;
console.log('attr demo value:', value);
alert(value);
'''})