Charts
Chart.js by default, ApexCharts for gauges. Both read the same JSON block.
How to use it
Copy any example below and paste it in- Marker
data-chartjs="line|area|bar|doughnut|pie|radar", ordata-chart="radial|donut|area"for ApexCharts.- Data
- A
<script type="application/json" data-chart-data>inside the container. Keeping it there is what lets the plugin load only where a chart exists. - Options
legend,stacked,horizontal, andformatfor a currency or percentage axis.- Caption
- Becomes the canvas
aria-label. A chart is a picture — give it one, and put the figures in a table nearby. - Theme
- Series colours come from
--color-chart-1…8, the first three of which are the accent. The chrome follows the theme and rebuilds onbrutalism:theme.
Area chart with a currency axis
<div data-chartjs="area" data-chart-height="260">
<script type="application/json" data-chart-data>
{
"labels": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
"series": [{ "name": "Revenue", "data": [7200, 8100, 9400, 8800, 10200, 11600, 9900] }],
"format": { "prefix": "$", "compact": true },
"caption": "Revenue rises from $7,200 on Monday to a peak of $11,600 on Saturday."
}
</script>
</div>
Grouped bars and a doughnut
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
<div data-chartjs="bar" data-chart-height="240">
<script type="application/json" data-chart-data>
{
"labels": ["Q1", "Q2", "Q3", "Q4"],
"series": [
{ "name": "Bookings", "data": [248, 262, 318, 274] },
{ "name": "Target", "data": [260, 280, 300, 300] }
],
"legend": true,
"caption": "Bookings beat target in Q3 only."
}
</script>
</div>
<div data-chartjs="doughnut" data-chart-height="240">
<script type="application/json" data-chart-data>
{
"labels": ["Web", "Mobile", "Marketplace", "Phone"],
"series": [{ "name": "Orders", "data": [1842, 1124, 412, 104] }],
"legend": true,
"caption": "Web takes 1,842 of 3,482 orders."
}
</script>
</div>
</div>
Radial gauge (ApexCharts)
<div data-chart="radial" data-chart-height="220">
<script type="application/json" data-chart-data>
{ "series": [78], "labels": ["78% of goal"], "caption": "Quota attainment is 78 percent." }
</script>
</div>
Stacked bars
Parts of a whole, period by period.
<div data-chartjs="bar" data-chart-height="260">
<script type="application/json" data-chart-data>
{
"labels": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
"series": [
{ "name": "Android", "data": [28, 31, 34, 32, 38, 41] },
{ "name": "iOS", "data": [19, 21, 23, 22, 26, 28] },
{ "name": "Web", "data": [11, 12, 14, 13, 16, 18] }
],
"stacked": true,
"legend": true,
"format": { "suffix": "K" },
"caption": "Downloads by platform, stacked. The total rises from 58K in January to 87K in June."
}
</script>
</div>
Horizontal bars
For category names too long to fit under a column.
<div data-chartjs="bar" data-chart-height="280">
<script type="application/json" data-chart-data>
{
"labels": ["Organic search", "Paid search", "Social", "Email", "Referral", "Direct"],
"series": [{ "name": "Sessions", "data": [4820, 3140, 2680, 1960, 1721, 980] }],
"horizontal": true,
"format": { "compact": true },
"caption": "Organic search leads with 4,820 sessions; direct is lowest at 980."
}
</script>
</div>
Multi-series line
Three measures on one scale.
<div data-chartjs="line" data-chart-height="280">
<script type="application/json" data-chart-data>
{
"labels": ["W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8"],
"series": [
{ "name": "Visitors", "data": [1200, 1380, 1290, 1640, 1580, 1870, 1960, 2140] },
{ "name": "Sign-ups", "data": [180, 210, 196, 268, 254, 312, 336, 384] },
{ "name": "Paid", "data": [42, 51, 48, 69, 64, 82, 91, 104] }
],
"legend": true,
"caption": "Visitors, sign-ups and paid conversions all trend up over eight weeks."
}
</script>
</div>
Pie and radar
A share breakdown, and a profile across several axes.
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
<div data-chartjs="pie" data-chart-height="260">
<script type="application/json" data-chart-data>
{
"labels": ["Permanent", "Fixed term", "Contractor", "Intern"],
"series": [{ "name": "People", "data": [1894, 348, 206, 72] }],
"legend": true,
"caption": "Permanent staff make up 1,894 of 2,520 people."
}
</script>
</div>
<div data-chartjs="radar" data-chart-height="260">
<script type="application/json" data-chart-data>
{
"labels": ["Speed", "Reliability", "Support", "Price", "Features", "Docs"],
"series": [
{ "name": "Us", "data": [88, 92, 78, 64, 85, 94] },
{ "name": "Market average", "data": [70, 74, 72, 76, 68, 58] }
],
"legend": true,
"caption": "Scored against the market average on six attributes; we lead everywhere except price."
}
</script>
</div>
</div>
Donut gauge with a figure (ApexCharts)
Two radial series on one dial.
<div data-chart="radial" data-chart-height="260">
<script type="application/json" data-chart-data>
{
"series": [86, 62],
"labels": ["Seats used", "Storage used"],
"caption": "86 percent of seats and 62 percent of storage are in use.",
"options": { "legend": { "show": true, "position": "bottom" } }
}
</script>
</div>