Charts
Bar, line, area, stacked bar, doughnut and sparkline charts with Chart.js, in the colours of the theme, with dark mode and a table for every chart.
Bar and line
A bar chart compares values across categories; a line chart shows a trend. The second line is dashed, so the two series differ by more than colour. Each canvas sits in an element with role="img" and an aria-label that says what the chart shows, and View as table swaps it for the same data as a real table, which screen reader and keyboard users can read.
Visitors per day
Revenue per month
- 2026
- 2025
<div
id="chart-visitors"
class="min-w-0 group/chart"
x-data='chartCard({"kind":"bar","data":{"format":"number","labels":["Oct 21","Oct 22","Oct 23","Oct 24","Oct 25","Oct 26","Oct 27","Oct 28","Oct 29","Oct 30","Oct 31","Nov 1","Nov 2","Nov 3"],"series":[{"name":"Visitors","data":[9100,9600,8800,5300,4900,9400,10200,10800,10100,9300,5800,5400,10500,7900]}]}})'
>
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<h3 id="chart-visitors-title" class="text-sm font-semibold text-dominant-900 dark:text-white">
Visitors per day
</h3>
<button
id="chart-visitors-toggle"
type="button"
aria-expanded="false"
aria-controls="chart-visitors-table"
x-on:click="table = !table"
x-text="table ? 'View as chart' : 'View as table'"
class="font-semibold rounded underline-offset-2 focus-visible:ring-2 focus-visible:outline-none cursor-pointer text-primary-700 dark:text-primary-300 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 underline hover:text-primary-800 dark:hover:text-primary-200 text-sm"
>
<span>View as table</span>
</button>
</div>
<div
role="img"
aria-label="Bar chart of visitors per day, from October 21 to November 3. Weekdays are higher, with about 10,000; weekends drop to about 5,000."
class="h-64 group-has-[[aria-expanded=true]]/chart:hidden"
>
<canvas x-ref="canvas"
>Bar chart of visitors per day, from October 21 to November 3. Weekdays are higher, with about
10,000; weekends drop to about 5,000.</canvas
>
</div>
<div
id="chart-visitors-table"
class="hidden overflow-auto max-h-64 rounded-lg border border-dominant-200 dark:border-dominant-700 group-has-[[aria-expanded=true]]/chart:block"
>
<table aria-labelledby="chart-visitors-title" class="w-full text-sm border-collapse">
<thead>
<tr>
<th
scope="col"
class="px-3 py-2 text-left font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
>
Period
</th>
<template x-for="s in data.series" x-bind:key="s.name">
<th
scope="col"
x-text="s.name"
class="px-3 py-2 text-right font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
></th>
</template>
</tr>
</thead>
<tbody>
<template x-for="(label, i) in data.labels" x-bind:key="label">
<tr>
<th
scope="row"
x-text="label"
class="px-3 py-2 align-top text-dominant-700 text-left font-medium text-dominant-900 dark:text-white dark:text-dominant-200 border-b border-dominant-200 dark:border-dominant-700"
></th>
<template x-for="s in data.series" x-bind:key="s.name">
<td
x-text="fmt(s.data[i])"
class="px-3 py-2 align-top text-dominant-700 dark:text-dominant-200 text-right tabular-nums border-b border-dominant-200 dark:border-dominant-700"
></td>
</template>
</tr>
</template>
</tbody>
</table>
</div>
</div>
<div
id="chart-revenue"
class="min-w-0 group/chart"
x-data='chartCard({"kind":"line","data":{"format":"currency","labels":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"series":[{"name":"2026","data":[18200,19400,22100,21000,24800,26300,25100,28900,30200,31800,33500,36400]},{"name":"2025","data":[15100,16300,17200,18900,19400,21000,20800,22600,23900,25100,26400,29800],"dashed":true}]}})'
>
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<h3 id="chart-revenue-title" class="text-sm font-semibold text-dominant-900 dark:text-white">
Revenue per month
</h3>
<button
id="chart-revenue-toggle"
type="button"
aria-expanded="false"
aria-controls="chart-revenue-table"
x-on:click="table = !table"
x-text="table ? 'View as chart' : 'View as table'"
class="font-semibold rounded underline-offset-2 focus-visible:ring-2 focus-visible:outline-none cursor-pointer text-primary-700 dark:text-primary-300 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 underline hover:text-primary-800 dark:hover:text-primary-200 text-sm"
>
<span>View as table</span>
</button>
</div>
<div
role="img"
aria-label="Line chart of revenue per month, 2026 compared with 2025. Both rise through the year; 2026 is higher every month and reaches $36,400 in December."
class="h-64 group-has-[[aria-expanded=true]]/chart:hidden"
>
<canvas x-ref="canvas"
>Line chart of revenue per month, 2026 compared with 2025. Both rise through the year; 2026 is
higher every month and reaches $36,400 in December.</canvas
>
</div>
<ul class="flex flex-wrap gap-x-5 gap-y-1 mt-3 text-sm">
<li class="flex items-center gap-2">
<span aria-hidden="true" class="size-2.5 bg-primary-700 dark:bg-primary-400 rounded-full">
</span>
<span class="text-dominant-900 dark:text-white">2026</span>
</li>
<li class="flex items-center gap-2">
<span
aria-hidden="true"
class="inline-block h-0 w-5 border-t-2 border-dashed border-dominant-600 dark:border-dominant-300"
>
</span>
<span class="text-dominant-900 dark:text-white">2025</span>
</li>
</ul>
<div
id="chart-revenue-table"
class="hidden overflow-auto max-h-64 rounded-lg border border-dominant-200 dark:border-dominant-700 group-has-[[aria-expanded=true]]/chart:block"
>
<table aria-labelledby="chart-revenue-title" class="w-full text-sm border-collapse">
<thead>
<tr>
<th
scope="col"
class="px-3 py-2 text-left font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
>
Period
</th>
<template x-for="s in data.series" x-bind:key="s.name">
<th
scope="col"
x-text="s.name"
class="px-3 py-2 text-right font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
></th>
</template>
</tr>
</thead>
<tbody>
<template x-for="(label, i) in data.labels" x-bind:key="label">
<tr>
<th
scope="row"
x-text="label"
class="px-3 py-2 align-top text-dominant-700 text-left font-medium text-dominant-900 dark:text-white dark:text-dominant-200 border-b border-dominant-200 dark:border-dominant-700"
></th>
<template x-for="s in data.series" x-bind:key="s.name">
<td
x-text="fmt(s.data[i])"
class="px-3 py-2 align-top text-dominant-700 dark:text-dominant-200 text-right tabular-nums border-b border-dominant-200 dark:border-dominant-700"
></td>
</template>
</tr>
</template>
</tbody>
</table>
</div>
</div>
Area and stacked bar
An area chart is a line with a soft fill, good for one quantity over time. A stacked bar splits each total into parts; with several series the colours are explained by a text legend, not only by the canvas.
Sessions this week
Orders per quarter by channel
- Online
- Retail
- Partners
<div
id="chart-sessions"
class="min-w-0 group/chart"
x-data='chartCard({"kind":"area","data":{"format":"number","labels":["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],"series":[{"name":"Sessions","data":[3200,4100,3900,4600,5200,2900,2400]}]}})'
>
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<h3 id="chart-sessions-title" class="text-sm font-semibold text-dominant-900 dark:text-white">
Sessions this week
</h3>
<button
id="chart-sessions-toggle"
type="button"
aria-expanded="false"
aria-controls="chart-sessions-table"
x-on:click="table = !table"
x-text="table ? 'View as chart' : 'View as table'"
class="font-semibold rounded underline-offset-2 focus-visible:ring-2 focus-visible:outline-none cursor-pointer text-primary-700 dark:text-primary-300 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 underline hover:text-primary-800 dark:hover:text-primary-200 text-sm"
>
<span>View as table</span>
</button>
</div>
<div
role="img"
aria-label="Area chart of sessions per day this week. Sessions peak on Friday at 5,200 and are lowest on Sunday at 2,400."
class="h-64 group-has-[[aria-expanded=true]]/chart:hidden"
>
<canvas x-ref="canvas"
>Area chart of sessions per day this week. Sessions peak on Friday at 5,200 and are lowest on
Sunday at 2,400.</canvas
>
</div>
<div
id="chart-sessions-table"
class="hidden overflow-auto max-h-64 rounded-lg border border-dominant-200 dark:border-dominant-700 group-has-[[aria-expanded=true]]/chart:block"
>
<table aria-labelledby="chart-sessions-title" class="w-full text-sm border-collapse">
<thead>
<tr>
<th
scope="col"
class="px-3 py-2 text-left font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
>
Period
</th>
<template x-for="s in data.series" x-bind:key="s.name">
<th
scope="col"
x-text="s.name"
class="px-3 py-2 text-right font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
></th>
</template>
</tr>
</thead>
<tbody>
<template x-for="(label, i) in data.labels" x-bind:key="label">
<tr>
<th
scope="row"
x-text="label"
class="px-3 py-2 align-top text-dominant-700 text-left font-medium text-dominant-900 dark:text-white dark:text-dominant-200 border-b border-dominant-200 dark:border-dominant-700"
></th>
<template x-for="s in data.series" x-bind:key="s.name">
<td
x-text="fmt(s.data[i])"
class="px-3 py-2 align-top text-dominant-700 dark:text-dominant-200 text-right tabular-nums border-b border-dominant-200 dark:border-dominant-700"
></td>
</template>
</tr>
</template>
</tbody>
</table>
</div>
</div>
<div
id="chart-orders"
class="min-w-0 group/chart"
x-data='chartCard({"kind":"stacked","data":{"format":"number","labels":["Q1","Q2","Q3","Q4"],"series":[{"name":"Online","data":[420,510,580,690]},{"name":"Retail","data":[310,330,290,360]},{"name":"Partners","data":[90,120,160,210]}]}})'
>
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<h3 id="chart-orders-title" class="text-sm font-semibold text-dominant-900 dark:text-white">
Orders per quarter by channel
</h3>
<button
id="chart-orders-toggle"
type="button"
aria-expanded="false"
aria-controls="chart-orders-table"
x-on:click="table = !table"
x-text="table ? 'View as chart' : 'View as table'"
class="font-semibold rounded underline-offset-2 focus-visible:ring-2 focus-visible:outline-none cursor-pointer text-primary-700 dark:text-primary-300 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 underline hover:text-primary-800 dark:hover:text-primary-200 text-sm"
>
<span>View as table</span>
</button>
</div>
<div
role="img"
aria-label="Stacked bar chart of orders per quarter by channel. Online grows from 420 to 690, retail stays near 300, partners grow from 90 to 210."
class="h-64 group-has-[[aria-expanded=true]]/chart:hidden"
>
<canvas x-ref="canvas"
>Stacked bar chart of orders per quarter by channel. Online grows from 420 to 690, retail
stays near 300, partners grow from 90 to 210.</canvas
>
</div>
<ul class="flex flex-wrap gap-x-5 gap-y-1 mt-3 text-sm">
<li class="flex items-center gap-2">
<span aria-hidden="true" class="size-2.5 bg-primary-700 dark:bg-primary-400 rounded-full">
</span>
<span class="text-dominant-900 dark:text-white">Online</span>
</li>
<li class="flex items-center gap-2">
<span aria-hidden="true" class="size-2.5 bg-info-700 dark:bg-info-400 rounded-full"> </span>
<span class="text-dominant-900 dark:text-white">Retail</span>
</li>
<li class="flex items-center gap-2">
<span aria-hidden="true" class="size-2.5 bg-warning-700 dark:bg-warning-400 rounded-full">
</span>
<span class="text-dominant-900 dark:text-white">Partners</span>
</li>
</ul>
<div
id="chart-orders-table"
class="hidden overflow-auto max-h-64 rounded-lg border border-dominant-200 dark:border-dominant-700 group-has-[[aria-expanded=true]]/chart:block"
>
<table aria-labelledby="chart-orders-title" class="w-full text-sm border-collapse">
<thead>
<tr>
<th
scope="col"
class="px-3 py-2 text-left font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
>
Period
</th>
<template x-for="s in data.series" x-bind:key="s.name">
<th
scope="col"
x-text="s.name"
class="px-3 py-2 text-right font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
></th>
</template>
</tr>
</thead>
<tbody>
<template x-for="(label, i) in data.labels" x-bind:key="label">
<tr>
<th
scope="row"
x-text="label"
class="px-3 py-2 align-top text-dominant-700 text-left font-medium text-dominant-900 dark:text-white dark:text-dominant-200 border-b border-dominant-200 dark:border-dominant-700"
></th>
<template x-for="s in data.series" x-bind:key="s.name">
<td
x-text="fmt(s.data[i])"
class="px-3 py-2 align-top text-dominant-700 dark:text-dominant-200 text-right tabular-nums border-b border-dominant-200 dark:border-dominant-700"
></td>
</template>
</tr>
</template>
</tbody>
</table>
</div>
</div>
Doughnut
A doughnut shows parts of a whole. The total sits in the middle as text, and the legend lists every part with its value and share, so the numbers are never only in the picture. Use it for a handful of parts; for more, use a bar chart.
Sessions by source
<div
id="chart-sources"
class="min-w-0 group/chart"
x-data='chartCard({"kind":"doughnut","data":{"format":"number","labels":["Direct","Search","Social","Referral"],"series":[{"name":"Sessions","data":[4200,3100,1700,1000]}]}})'
>
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<h3 id="chart-sources-title" class="text-sm font-semibold text-dominant-900 dark:text-white">
Sessions by source
</h3>
<button
id="chart-sources-toggle"
type="button"
aria-expanded="false"
aria-controls="chart-sources-table"
x-on:click="table = !table"
x-text="table ? 'View as chart' : 'View as table'"
class="font-semibold rounded underline-offset-2 focus-visible:ring-2 focus-visible:outline-none cursor-pointer text-primary-700 dark:text-primary-300 focus-visible:ring-primary-700 dark:focus-visible:ring-primary-400 underline hover:text-primary-800 dark:hover:text-primary-200 text-sm"
>
<span>View as table</span>
</button>
</div>
<div
role="img"
aria-label="Doughnut chart of 10,000 sessions by source: direct 42%, search 31%, social 17%, referral 10%."
class="h-64 group-has-[[aria-expanded=true]]/chart:hidden"
>
<canvas x-ref="canvas"
>Doughnut chart of 10,000 sessions by source: direct 42%, search 31%, social 17%, referral
10%.</canvas
>
</div>
<div
id="chart-sources-table"
class="hidden overflow-auto max-h-64 rounded-lg border border-dominant-200 dark:border-dominant-700 group-has-[[aria-expanded=true]]/chart:block"
>
<table aria-labelledby="chart-sources-title" class="w-full text-sm border-collapse">
<thead>
<tr>
<th
scope="col"
class="px-3 py-2 text-left font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
>
Period
</th>
<template x-for="s in data.series" x-bind:key="s.name">
<th
scope="col"
x-text="s.name"
class="px-3 py-2 text-right font-semibold text-dominant-900 dark:text-white bg-dominant-50 dark:bg-dominant-800 border-b border-dominant-300 dark:border-dominant-600"
></th>
</template>
</tr>
</thead>
<tbody>
<template x-for="(label, i) in data.labels" x-bind:key="label">
<tr>
<th
scope="row"
x-text="label"
class="px-3 py-2 align-top text-dominant-700 text-left font-medium text-dominant-900 dark:text-white dark:text-dominant-200 border-b border-dominant-200 dark:border-dominant-700"
></th>
<template x-for="s in data.series" x-bind:key="s.name">
<td
x-text="fmt(s.data[i])"
class="px-3 py-2 align-top text-dominant-700 dark:text-dominant-200 text-right tabular-nums border-b border-dominant-200 dark:border-dominant-700"
></td>
</template>
</tr>
</template>
</tbody>
</table>
</div>
</div>
Sparkline
A small line without axes beside a number, in a stat card. It only hints at the direction, so it is hidden from assistive technology (aria-hidden) and the change is written as text (“Up +12.4% vs last month”) with an arrow icon, never as colour alone. The colour follows the trend; variant changes it when a fall is good, and note adds a neutral line. It has no tooltip and takes no mouse events.
Revenue
$17,400
Up +12.4% vs last month
Orders
1,248
Up +7.9% vs last month
Conversion
2.8%
Down -0.6% vs last month
Costs
$6,210
Down -8.1% vs last month
Lower is better.
Churn
4.3%
Up +0.9% vs last month
Target: below 3%.
Sessions
38,902
Up +1.2% vs last month
Includes internal traffic.
<div
id="sparkline-1516"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[9,11,10,13,12,15,14,17]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Revenue</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">$17,400</p>
<p class="mt-1 text-xs font-medium text-success-700 dark:text-success-300">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-up"> </i>
<span class="sr-only">Up</span>
<span>+12.4% vs last month</span>
</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
<div
id="sparkline-1647"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[120,132,125,140,138,151,149,160]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Orders</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">1,248</p>
<p class="mt-1 text-xs font-medium text-success-700 dark:text-success-300">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-up"> </i>
<span class="sr-only">Up</span>
<span>+7.9% vs last month</span>
</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
<div
id="sparkline-1722"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[3.4,3.2,3.3,3.1,3,3.1,2.9,2.8]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Conversion</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">2.8%</p>
<p class="mt-1 text-xs font-medium text-danger-700 dark:text-danger-300">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-down"> </i>
<span class="sr-only">Down</span>
<span>-0.6% vs last month</span>
</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
<div
id="sparkline-costs"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[82,80,78,74,73,69,66,62]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Costs</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">$6,210</p>
<p class="mt-1 text-xs font-medium text-success-700 dark:text-success-300">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-down"> </i>
<span class="sr-only">Down</span>
<span>-8.1% vs last month</span>
</p>
<p class="mt-1 text-xs text-dominant-600 dark:text-dominant-300">Lower is better.</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
<div
id="sparkline-churn"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[2.9,3.1,3,3.4,3.6,3.9,4.1,4.3]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Churn</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">4.3%</p>
<p class="mt-1 text-xs font-medium text-danger-700 dark:text-danger-300">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-up"> </i>
<span class="sr-only">Up</span>
<span>+0.9% vs last month</span>
</p>
<p class="mt-1 text-xs text-dominant-600 dark:text-dominant-300">Target: below 3%.</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
<div
id="sparkline-sessions"
class="flex items-center justify-between gap-3 p-4 bg-white dark:bg-dominant-900 rounded-xl border border-dominant-200 dark:border-dominant-700"
x-data='chartCard({"kind":"spark","data":{"labels":[0,1,2,3,4,5,6,7],"series":[{"data":[370,372,369,378,381,380,386,389]}]}})'
>
<div class="min-w-0">
<p class="text-sm text-dominant-700 dark:text-dominant-200">Sessions</p>
<p class="mt-1 text-2xl font-bold text-dominant-900 dark:text-white">38,902</p>
<p class="mt-1 text-xs font-medium text-dominant-700 dark:text-dominant-200">
<i aria-hidden="true" class="fa-solid fa-arrow-trend-up"> </i>
<span class="sr-only">Up</span>
<span>+1.2% vs last month</span>
</p>
<p class="mt-1 text-xs text-dominant-600 dark:text-dominant-300">Includes internal traffic.</p>
</div>
<div aria-hidden="true" class="shrink-0 h-12 w-24">
<canvas x-ref="canvas"> </canvas>
</div>
</div>
Options reference
The charts are Chart.js drawn on a canvas; the page keeps the theme, the data and the table in one small Alpine component.
| Part | Value | Description |
|---|---|---|
| Library |
chart.js@4.6.1
|
Loaded from the CDN before Alpine, as in the layouts. Use the UMD build: chart.umd.min.js.
|
chartCard(key, kind)
|
Alpine component |
Draws DATA[key]. Kinds: bar, stacked, line, area, doughnut, spark. Put a <canvas x-ref="canvas"> inside.
|
DATA[key]
|
{ format, labels, series }
|
format is number, currency or percent. A series is { name, data, dashed? }.
|
| Size | parent element |
The chart fills its parent (maintainAspectRatio: false), so give the parent a height such as h-64.
|
| Colours |
THEME
|
Hex values of the Starkit theme: the 700 shade on a light surface, the 400 shade on a dark one, with grid and text colours for each. Canvas cannot use Tailwind classes, so keep the values in one place. |
| Dark mode | automatic |
A MutationObserver on the class of <html> redraws the chart when the theme changes, without a reload.
|
| Accessibility |
role="img", aria-label, table
|
Describe the chart in the label, repeat the numbers in the table (View as table) and in a text legend. Decorative sparklines are aria-hidden.
|
| Motion |
prefers-reduced-motion
|
Animation is turned off when the person asks for reduced motion. |
| Tooltips | mouse only | Chart.js tooltips need a pointer; the table is the keyboard and touch alternative. |