Charts
One hook, one JSON attribute, nine chart types and a sparkline mode. Colours come from the resolved tokens rather than a palette in the config, so switching preset or mode re-themes every chart on the page in place — try it while you read.
How a chart is declared
An empty element with data-av-chart and a
data-av-chart-options JSON payload. The vendor is lazy-loaded when the
element scrolls into view, so a page with a chart below the fold pays nothing for it
until it is needed.
A chart is an image, so give it a description
Every chart here carries role="img" and an
aria-label that states the actual figures. A canvas of SVG paths is
unreadable to a screen reader and to anyone who cannot distinguish the series
colours; the label is the chart, for them. Write what the chart says, not
that it is a chart.
<div data-av-chart
data-av-chart-options='{
"type": "area", "height": 260, "moneyAxis": true,
"categories": ["Mar","Apr","May","Jun","Jul","Aug"],
"series": [{ "name": "Revenue", "data": [18200, 21400, 20100, 24800, 27300, 31200] }]
}'
role="img"
aria-label="Area chart of monthly revenue rising from 18,200 euros in March to 31,200 in August, with a dip to 20,100 in May."></div>
Trend
Something over time. Area for one series, line once there are several — stacked translucent fills stop being readable at about two.
<div data-av-chart
data-av-chart-options='{
"type": "line", "height": 280,
"categories": ["Mar","Apr","May","Jun","Jul","Aug"],
"series": [
{ "name": "Organic", "data": [4200, 4800, 5100, 5600, 6100, 6400] },
{ "name": "Paid", "data": [3100, 3400, 3200, 3900, 4300, 4100] },
{ "name": "Referral","data": [1200, 1500, 1900, 2100, 2400, 2900] },
{ "name": "Direct", "data": [900, 1100, 1000, 1300, 1500, 1700] }
]
}'
role="img"
aria-label="Line chart of sessions by channel, March to August. Organic grows from 4,200 to 6,400; paid from 3,100 to 4,100; referral from 1,200 to 2,900; direct from 900 to 1,700."></div>
31,204
3.9%
<div class="av-grid av-grid--stats">
<div class="av-stat-card">
<div class="av-stat-card__head">
<span class="av-stat-card__label">Sessions</span>
</div>
<p class="av-stat-card__value">31,204</p>
<div data-av-chart
data-av-chart-options='{
"type": "area", "height": 60, "legend": false, "sparkline": true,
"series": [{ "name": "Sessions", "data": [18, 22, 20, 27, 25, 31, 34] }]
}'
role="img"
aria-label="Sparkline of sessions over seven days, rising from 18 to 34 thousand."></div>
</div>
<div class="av-stat-card">
<div class="av-stat-card__head">
<span class="av-stat-card__label">Conversion</span>
</div>
<p class="av-stat-card__value">3.9%</p>
<div data-av-chart
data-av-chart-options='{
"type": "area", "height": 60, "legend": false, "sparkline": true,
"series": [{ "name": "Conversion", "data": [42, 40, 44, 41, 45, 47, 39] }]
}'
role="img"
aria-label="Sparkline of conversion rate over seven days, hovering around 4 percent and dipping on the last day."></div>
</div>
</div>
Comparison
Bars compare quantities across categories. Go horizontal the moment the labels are words rather than dates — rotated axis labels are a design admitting it ran out of room.
<div data-av-chart
data-av-chart-options='{
"type": "bar", "height": 300, "stacked": true, "moneyAxis": true,
"categories": ["Mar","Apr","May","Jun","Jul","Aug"],
"series": [
{ "name": "New", "data": [4200, 4800, 5100, 5600, 6100, 6400] },
{ "name": "Expansion", "data": [1800, 2100, 2400, 2600, 3100, 3400] },
{ "name": "Churned", "data": [-1400, -1200, -1600, -1300, -1100, -900] }
]
}'
role="img"
aria-label="Stacked bar chart of monthly recurring revenue movement: new business rising from 4,200 to 6,400 euros, expansion from 1,800 to 3,400, churn shrinking from 1,400 to 900."></div>
<div data-av-chart
data-av-chart-options='{
"type": "bar", "height": 280, "horizontal": true, "moneyAxis": true, "legend": false,
"categories": ["Canvas backpack","Mechanical keyboard","Water bottle","Sunglasses","Cable roll"],
"series": [{ "name": "Revenue", "data": [28400, 19100, 12600, 9400, 6200] }]
}'
role="img"
aria-label="Horizontal bar chart of revenue by product: canvas backpack 28,400 euros, mechanical keyboard 19,100, water bottle 12,600, notebook set 9,400, cable roll 6,200."></div>
Composition
Parts of a whole. labels replaces categories here — and it
must be absent rather than undefined on the other types,
because Apex reads .length off it while laying out a bar and throws.
<div style="flex: 1; min-inline-size: 260px">
<div data-av-chart
data-av-chart-options='{
"type": "donut", "height": 280,
"labels": ["Starter","Team","Business","Enterprise"],
"series": [842, 664, 318, 88]
}'
role="img"
aria-label="Donut chart of plan mix: Starter 842 accounts, Team 664, Business 318, Enterprise 88."></div>
</div>
<div style="flex: 1; min-inline-size: 260px">
<div data-av-chart
data-av-chart-options='{
"type": "pie", "height": 280,
"labels": ["Desktop","Mobile","Tablet"],
"series": [58, 34, 8]
}'
role="img"
aria-label="Pie chart of sessions by device: desktop 58 percent, mobile 34, tablet 8."></div>
</div>
<div data-av-chart
data-av-chart-options='{
"type": "radialBar", "height": 300,
"labels": ["Storage","Bandwidth","Seats"],
"series": [68, 42, 91]
}'
role="img"
aria-label="Radial bar chart of plan usage: storage 68 percent, bandwidth 42 percent, seats 91 percent."></div>
Specialist
Same hook, same theming. These take a different series shape, which is
the only thing that changes.
<div data-av-chart
data-av-chart-options='{
"type": "candlestick", "height": 300, "legend": false,
"categories": ["04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00"],
"series": [{ "name": "BTC/EUR", "data": [
{ "x": "04:00", "y": [58200, 58640, 58010, 58480] },
{ "x": "05:00", "y": [58480, 58720, 58240, 58300] },
{ "x": "06:00", "y": [58300, 58390, 57840, 57960] },
{ "x": "07:00", "y": [57960, 58510, 57920, 58460] },
{ "x": "08:00", "y": [58460, 59120, 58400, 59040] },
{ "x": "09:00", "y": [59040, 59380, 58880, 58940] },
{ "x": "10:00", "y": [58940, 59260, 58760, 59180] },
{ "x": "11:00", "y": [59180, 59840, 59120, 59720] }
]}]
}'
role="img"
aria-label="Candlestick chart of BTC against the euro from 04:00 to 11:00, opening at 58,200 and closing at 59,720 with a dip to 57,840 at 06:00."></div>
<div data-av-chart
data-av-chart-options='{
"type": "heatmap", "height": 260, "legend": false,
"series": [
{ "name": "Mon", "data": [{"x":"09","y":12},{"x":"11","y":38},{"x":"13","y":54},{"x":"15","y":41},{"x":"17","y":22}] },
{ "name": "Tue", "data": [{"x":"09","y":18},{"x":"11","y":44},{"x":"13","y":61},{"x":"15","y":49},{"x":"17","y":26}] },
{ "name": "Wed", "data": [{"x":"09","y":21},{"x":"11","y":51},{"x":"13","y":72},{"x":"15","y":58},{"x":"17","y":31}] },
{ "name": "Thu", "data": [{"x":"09","y":16},{"x":"11","y":39},{"x":"13","y":57},{"x":"15","y":44},{"x":"17","y":28}] },
{ "name": "Fri", "data": [{"x":"09","y":11},{"x":"11","y":29},{"x":"13","y":36},{"x":"15","y":25},{"x":"17","y":14}] }
]
}'
role="img"
aria-label="Heatmap of support tickets by weekday and hour. Volume peaks on Wednesday at 13:00 with 72 tickets and is lightest on Friday at 17:00 with 14."></div>
<div data-av-chart
data-av-chart-options='{
"type": "radar", "height": 320,
"categories": ["Speed","Reliability","Support","Pricing","Features","Docs"],
"series": [
{ "name": "Us", "data": [88, 92, 74, 61, 83, 90] },
{ "name": "Competitor", "data": [71, 84, 88, 79, 66, 58] }
]
}'
role="img"
aria-label="Radar chart comparing us with a competitor across six measures. We lead on speed 88 to 71, reliability 92 to 84, features 83 to 66 and documentation 90 to 58; the competitor leads on support 88 to 74 and pricing 79 to 61."></div>
<div data-av-chart
data-av-chart-options='{
"type": "treemap", "height": 320,
"series": [{ "data": [
{ "x": "Direct", "y": 4180 },
{ "x": "Organic", "y": 3240 },
{ "x": "Referral", "y": 1890 },
{ "x": "Email", "y": 1120 },
{ "x": "Social", "y": 860 },
{ "x": "Paid", "y": 640 },
{ "x": "Affiliate","y": 310 }
] }]
}'
role="img"
aria-label="Treemap of sessions by acquisition channel. Direct is largest at 4,180, then organic 3,240, referral 1,890, email 1,120, social 860, paid 640 and affiliate 310."></div>
<div data-av-chart
data-av-chart-options='{
"mixed": true, "height": 320,
"categories": ["Jan","Feb","Mar","Apr","May","Jun"],
"series": [
{ "name": "Revenue", "type": "column", "data": [42, 47, 51, 49, 58, 63] },
{ "name": "Margin", "type": "line", "data": [28, 30, 29, 33, 35, 38] }
]
}'
role="img"
aria-label="Combination chart. Revenue columns rise from 42 to 63 thousand across six months, with a dip in April; the margin line rises from 28 to 38 percent over the same period."></div>
<div data-av-chart
data-av-chart-options='{
"funnel": true, "height": 320,
"categories": ["Visited","Signed up","Activated","Subscribed","Renewed"],
"series": [{ "name": "Accounts", "data": [12400, 5820, 3140, 1260, 940] }]
}'
role="img"
aria-label="Funnel of account progression. 12,400 visited, 5,820 signed up, 3,140 activated, 1,260 subscribed and 940 renewed."></div>
Options
Everything the wrapper reads. Anything not listed here is passed through to ApexCharts untouched.
| Key | Default | Effect |
|---|---|---|
type | area | Any ApexCharts type. |
height | 300 | Pixels. |
series | [] | Required. Shape depends on the type. |
categories | [] | X-axis labels. |
labels | absent | For donut, pie and radial bar. Must be absent, never undefined. |
stacked | false | Stack the series. |
horizontal | false | Rotate a bar chart. Moves moneyAxis with it. |
moneyAxis | false | Format the value axis as currency via Intl. |
legend | true | Set false for a single series. |
sparkline | false | Strip axes, grid and internal offsets so the shape fills its box. |
colors | from tokens | Override. Rarely right — the default re-themes with the preset. |
Why the colours are not in the config
The wrapper reads the resolved custom properties at render time and subscribes to
theme changes, so a preset or mode switch re-themes every chart in place rather than
leaving a blue line on a warm page. Both the first render and the re-theme go through
one buildOptions(): when those drifted apart, a theme change silently
dropped the axis categories and the value formatter, and the chart came back looking
fine and reading wrong.
Two other things the module does that a page never sees. A chart is
destroyed the moment its element leaves the document, by a
MutationObserver rather than on the next scan — an Apex chart keeps its own resize
observer, re-measures a parent that no longer exists, and writes
NaN into the SVG geometry, which is one console error per attribute on
every navigation away. And mount() re-checks
isConnected after awaiting the vendor, because the element can be gone
by the time a lazy import resolves.