Chart
The <x-wirekit-chart /> component renders charts with automatic WireKit theming. WireKit ships two built-in adapters — chartjs (default, MIT-licensed) and apexcharts (optional, non-MIT — see License below). Both use the same Blade tag; switching is a single config-line change.
Charts are disabled by default: enable them in config/ before mounting the component.
Choosing a chart library
| Need | Pick |
|---|---|
| Simple bar / line / pie / radar / scatter charts. MIT license. Smallest bundle. | Chart.js |
| Financial charts (candlestick, OHLC), heatmaps, treemaps, range-bars, sparklines. Polished defaults. | ApexCharts |
| Both — pick per-page via config | Either; the public <x-wirekit-chart> Blade tag is identical for both |
The choice happens once in config/ and applies as the application default. Two demo subhierarchies on the docs site walk every chart-type variation each library supports:
- Chart.js demo gallery — every chart family Chart.js ships natively, with realistic seed data
- ApexCharts demo gallery — every ApexCharts chart family including financial charts, sparklines, annotations, real-time streaming
Individual charts can override the default with the library prop — pass library="apexcharts" (or library="chartjs", or a custom adapter FQCN) on a single <x-wirekit-chart> tag and that chart binds to the named adapter regardless of the global config. Useful when one page mixes ApexCharts-only types (boxplot, candlestick, heatmap, treemap) with Chart.js elsewhere in a Chart.js-default app, without flipping the global setting.
Requirements
When using Chart.js (charts.library => 'chartjs')
Install Chart.js via npm:
npm install chart.js
Import and register in your app.js:
import { Chart, registerables } from 'chart.js';
Chart.register(...registerables);
When using ApexCharts (charts.library => 'apexcharts')
Install ApexCharts via npm:
npm install apexcharts
Supported versions: ApexCharts 5, 6, 7 and 8, each first verified in a real browser against 5.16.0, 6.10.0, 7.1.0 and 8.3.1. Every week the browser tests of the ApexCharts adapter run once per major, against the latest release of that major. A major bump on the ApexCharts side does not need a WireKit release to go with it: if you pin the version, pin it for your own reasons rather than out of concern that the adapter has a ceiling.
php artisan wirekit:verify names the version you have and says whether it falls inside that range, so you do not have to come back to this page to find out. A version outside it is a warning rather than an error — it may well work, nobody has measured it yet, and a chart that breaks on a new major breaks silently: the page renders, the markup is correct, and only a browser shows the empty box. If you run one, we would like to hear how it went.
Import and expose globally in your app.js:
import ApexCharts from 'apexcharts';
window.ApexCharts = ApexCharts;
Then switch the adapter on in config/:
// 1. Load WireKit's ApexCharts glue alongside the main bundle.
// Off by default so an app without charts ships no chart code.
'scripts' => [
'bundle' => 'full',
'apex' => true,
],
@wirekitScripts now emits both tags, in the order the adapter needs.
To load the adapter only where a chart is drawn, set 'apex' => 'on-demand'. No page then carries the adapter's tag: a chart drawn with ApexCharts names the adapter's address, and WireKit's script loads it when the first such chart starts, on a page wire:navigate brings and in a lazy island too. That chart draws once the adapter is in, a moment after the page has started.
// 2. Load the adapter on the pages that draw an ApexCharts chart, and on no other.
'scripts' => [
'bundle' => 'full',
'apex' => 'on-demand',
],
A missing adapter fails quietly: the page renders and only the chart is absent. Open the console — wirekit means this option is still off.
If you write your own script tags instead of using @wirekitScripts, the adapter goes below the main bundle:
{{-- 1. The library itself, which registers WireKit's Alpine components. --}}
<script src="{{ asset('vendor/wirekit/wirekit.js') }}" defer></script>
{{-- 2. The ApexCharts glue, which registers itself against it — so it comes second. --}}
<script src="{{ asset('vendor/wirekit/wirekit-apex.js') }}" defer></script>
The adapter bundle (dist/, size in Dependencies) registers the wirekit Alpine factory. It contains zero ApexCharts code — the JS library you installed via npm is what does the actual rendering.
ApexCharts is not MIT-licensed. The free Community License covers personal use, non-profits, education, and organizations under $2 million USD annual revenue. Above that threshold you must purchase a Commercial License directly from ApexCharts. WireKit ships only the adapter glue (MIT); the ApexCharts JS library is your responsibility to install and license. See the License section below for details.
Charts must have the @wirekitScripts directive in your layout — without it the canvas mounts and nothing draws on it. Both the full and core bundles include the Chart.js Alpine component. The ApexCharts adapter ships as a separate wirekit-apex.js bundle so developers who don't use ApexCharts pay zero bytes. See Getting Started for setup details.
Setup
Enable charts in config/:
'charts' => [
'library' => 'chartjs',
],
Or 'apexcharts':
'charts' => [
// 1. Switch the active adapter — the Blade tag stays the same.
'library' => 'apexcharts',
// 2. Optional: declare your ApexCharts license tier.
// Acceptable values: 'community' (default — under $2M USD revenue),
// 'commercial' (paid subscription), 'oem' (redistribution license).
// The wirekit:doctor reminder is suppressed for 'commercial' / 'oem'.
'apex_license' => 'community',
],
Usage
Pass labels and datasets as arrays — data can come from Eloquent, an API, or inline values:
<x-wirekit-chart
type="bar"
:labels="$stats->pluck('month')->toArray()"
:datasets="[
['label' => 'Revenue', 'data' => $stats->pluck('revenue')->toArray()],
['label' => 'Costs', 'data' => $stats->pluck('costs')->toArray()],
]"
/>
Or with inline data for quick prototyping:
<x-wirekit-chart
type="bar"
:labels="['Jan', 'Feb', 'Mar', 'Apr']"
:datasets="[
['label' => 'Revenue', 'data' => [12400, 15800, 18200, 16900]],
['label' => 'Costs', 'data' => [8200, 9100, 10400, 11200]],
]"
/>
Width & Layout
The chart fills its parent width and uses the height prop for its vertical dimension (default: 380px). Control width via the parent:
<div class="max-w-xl">
<x-wirekit-chart type="bar" height="250px" :labels="$labels" :datasets="$datasets" aria-label="Orders by weekday" />
</div>
Charts are responsive by default — they resize when the parent container changes width.
A class that sets a display or a position reaches the chart: class="hidden md:block" hides it on a phone and draws it at full width from md up, and class="absolute inset-0" takes it out of the flow. Its width stays with the parent.
A chart that renders more than its drawing renders all of it inside one element: its data table (table), the list of its points that link somewhere, and the wrapper of replayable and of every chart with wire-stream. In a grid or a flex row that element takes one place, and the table stands under the chart. It takes the class, wire:key and x-show you give the chart, so class="col-span-2" places the chart and its table together. style, id and the ARIA attributes stay on the drawing, where its height is.
Long axis labels
ApexCharts shortens an axis label that runs past labels.maxWidth and ends it with "...". A shortened label shows its full text in a tooltip while the pointer is on it, and after a touch until the next touch elsewhere. A label drawn whole shows none. The tooltip can be hovered, and Escape closes it. Pass :label-tips="false" to leave the labels as the library draws them. Chart.js never shortens its labels: it turns or skips them instead.
<x-wirekit-chart
type="bar"
library="apexcharts"
:labels="$repositories"
:datasets="$runs"
:options="['plotOptions' => ['bar' => ['horizontal' => true]], 'yaxis' => ['labels' => ['maxWidth' => 120]]]"
table
aria-label="Runs per repository this week"
/>
The chart is an image to a screen reader, and nothing inside it takes the focus, so the keyboard and a screen reader reach every label in full through the data table.
The first and the last name of an ApexCharts x-axis stay inside the drawing. On a phone ApexCharts turns the names of an axis that has no room for them, and the first one runs down to the left of the first point. After each draw the chart measures its labels, and where one runs past an edge, it widens the grid's padding on that side by as much. A grid.padding you set for a side in options, or for every chart in window.Apex, stays as you set it, and the chart adds nothing on that side.
Tooltip value formatting
ApexCharts tooltips print the raw numeric value at the hovered point — for float data that means the full 64-bit representation (50.523626895740676). The valueDecimals prop rounds it; valuePrefix / valueSuffix wrap it with a currency symbol or unit. All three are no-ops on the Chart.js adapter (its tooltip path is configured separately through options).
Hover any point: the tooltip reads 58.91 ms instead of 58.910020000000001.
The three props write the values of the tooltip, of the data table and of the links on the points. The y-axis the chart labels itself writes the bare number: grouped as the values are, and with the decimals a series names for itself (below), but without valueDecimals, valuePrefix or valueSuffix, so a unit does not widen the axis on every tick. The measure and its unit go once into the axis title, as p95 latency (ms) does in the preview above:
{{-- 1. The tooltip writes "58.91 ms", and the title beside the y-axis names the measure and its unit. --}}
<x-wirekit-chart library="apexcharts" type="line" valueDecimals="2" valueSuffix=" ms"
:labels="$minutes" :datasets="$latency"
:options="['yaxis' => ['title' => ['text' => 'p95 latency (ms)']]]" />
A bar that lies writes its values along the x-axis, so its title goes into xaxis.. With Chart.js the titles are scales.y.title and scales.x.title, each with display: true beside its text.
A series can name its own decimals with decimals on its dataset, which take the place of
valueDecimals for that series, in its tooltip rows and on the y-axis that shows it:
['label' => 'Returned units', 'data' => $units, 'decimals' => 0] beside a rate written with
value. Mixed charts show the case it
is for.
A tooltip. or a yaxis. set for every chart through ApexCharts' global options (window.Apex) writes the values of the ApexCharts tooltip, and a tooltip. the name in front of each value, as they do in ApexCharts; what they return is written as text. valueDecimals, valuePrefix and valueSuffix belong to the chart and come first: where one of them is set, the global formatter does not write that chart's values. The tooltip also reads tooltip., which series it lists at all, tooltip., which lists them from the last, and tooltip., which gives a value of zero no row, from the chart's options:
{{-- 1. A shared tooltip that lists the second series only, and leaves out a value of zero. --}}
<x-wirekit-chart library="apexcharts" type="line" :labels="$days" :datasets="$series"
:options="['tooltip' => ['shared' => true, 'enabledOnSeries' => [1], 'hideEmptySeries' => true]]" />
Numbers and dates follow your application's locale (app()->get), not the reader's browser, like the other WireKit components that format on the client: Chart.js receives it as its locale option, and an ApexCharts chart uses it for the dates in its tooltip, for its values and for its axis ticks, so a German page reads 58,91 ms. Set locale in options to choose another one for a single Chart.js chart.
An ApexCharts chart groups the thousands of its values the locale's way, in its tooltip, in the cells of a treemap and on the y-axis it labels itself: 278.984,46 in German. value-grouping="false" writes the digits ungrouped. An application that writes its numbers in its own format through WireKit:: hands every chart the grouping mark and the decimal mark that format writes.
The ApexCharts tooltip also names the rows a point brings without a series name: Open price, High, Low and Close price for a candlestick, Max, Median and Min for a boxplot, with the quartile symbols Q1 and Q3, and Size for a bubble. These names come from WireKit's translation catalog, so they follow the same locale.
On a date axis ('xaxis' => ['type' => 'datetime']), the ApexCharts tooltip titles each point with its date, whether the point gives x as a timestamp, as a date string or as the first value of a pair, and a timeline writes the two ends of each range the same way. Both follow tooltip., which is ApexCharts' own dd MMM until you set one such as 'MMM dd, yyyy HH:mm', with month and weekday names in your application's locale. They are written in UTC, as the axis is labeled, unless xaxis. is false, which writes the axis and the tooltip in the reader's time zone. A tooltip. or an xaxis. set for every chart through ApexCharts' global options (window.Apex) titles the point in place of the format, as it does in ApexCharts, and what it returns is written as text. The ends of a range column or a range area are values rather than dates, so the tooltip writes them as values.
A date on such an axis may also be a date object, such as a model attribute with a date cast, or a date and time written as text without a time zone. The chart hands each to the library in the form that labels the time it names: on an axis in UTC, 2026-12-25 10:00:00 reads 10:00 for every reader, and a day from a date cast stays that day. On an axis in the reader's time zone, a date object is its instant, shown in each reader's zone, and a date alone is that day for every reader. Text with a time zone and a timestamp in milliseconds name an instant and reach the library as they are. A Chart.js time scale is an axis in the reader's time zone, and the two ends of a timeline are written the same way.
A further value in the tooltip
A tooltip can name a value of the point that the chart does not draw, such as the number of
receipts of a day beside its revenue, where a series of its own would take an axis and an entry in
the legend. tooltipExtras gives a label and one value per point, in the order of labels, and the
tooltip names the value of the point it shows under the series' values:
Pass a list of them for more than one. Each extra writes its values in your application's locale
and takes its own decimals, prefix and suffix, so a count of receipts takes no currency sign
from the chart's valuePrefix. A point whose value is null has no row. The values follow a
Livewire update with the rest of the data, and the tooltip names them under Chart.js and
ApexCharts alike.
Linking data points
A point can lead somewhere: the report behind a day's revenue, the list behind a category. Give a
dataset urls, one address per point in the order of its data, with null for a point that
leads nowhere. A point written as an object, the way a treemap or a bubble chart writes its points,
takes its own url instead, and where both name one the point's own wins.
A click or a tap on a point follows its address the way a link does, and over a point with an address the pointer becomes a hand:
- An address on your site goes through Livewire's navigation where the page runs Livewire, as a
wire:navigatelink does. Another site, or amailto:address, goes through the browser. - Ctrl, Cmd or Shift with the click, or the middle button, opens it in a new tab.
- An address that is only a fragment,
#revenue-mon, jumps within the page. - An address whose scheme could run script, such as
javascript:, is dropped, so a point from your data never runs code in the page.
With ApexCharts a click follows the point its tooltip shows at that moment. A point a stream adds
through wireStream carries no address.
A point drawn on a canvas, or inside the chart's image, cannot take the focus. So the chart lists
the links of its points after itself, each named by what it shows: its label and value, as in
"Mon: €1,240", led by the dataset's name where the chart has more than one. The list is out of sight
until Tab reaches a link in it, and then stands under the chart until the focus leaves it. A screen
reader reads it after the chart's name. valueDecimals, valuePrefix and valueSuffix write the
values in the list under either library.
A point written as a pair is named the way its library draws it. [x, y] is named by its x and its
value. The pair of a Chart.js bar is a floating bar, named by its two ends, as in "Q1: 3 – 7". On a
date axis, an ApexCharts datetime axis or a Chart.js time scale, a point is named by its date,
written the way the tooltip writes one without a format of your own, as in "Jan 01, 2026: 3". A
tooltip. of your own changes the tooltip, not the list.
Chart Types
<x-wirekit-chart> accepts a type prop that maps to either Chart.js or ApexCharts depending on which library is registered as the active adapter (see Setup above). The two adapters share the WireKit data shape — same labels, same datasets, same options deep-merge — so swapping the active adapter changes the rendering library without touching the developer's Blade markup.
The preview above is the canonical <x-wirekit-chart> API in its smallest form: a type=, a labels array, one dataset. The dedicated demo pages under Chart.js Demos and ApexCharts Demos carry the per-type live previews + Blade snippets. The table below maps each canonical chart type to its demo page on each adapter so you can compare the rendering side by side before picking a library.
type= |
Chart.js demo | ApexCharts demo | Notes |
|---|---|---|---|
bar |
Bar | Bar / Column | Vertical on both adapters. ApexCharts additionally accepts column, which maps onto bar and renders identically; rotate the bars there with plotOptions.bar.horizontal |
line |
Line | Line | ApexCharts draws smooth curves by default and Chart.js straight segments; stroke.curve (ApexCharts) or a dataset's tension (Chart.js) changes it |
area |
Area | Area | Filled-line variant. Chart.js uses fill: true on the dataset, fill: 'stack' on a stacked axis; ApexCharts uses chart.type: 'area' |
pie |
Advanced | Pie / Donut | Both adapters expect a single dataset with data as a flat numeric array + top-level labels per slice |
doughnut |
Advanced | Pie / Donut | Same data shape as pie; ring-shape variant |
radar |
Advanced | Radar | Polygon chart for multi-axis comparison |
scatter |
Advanced | Scatter / Bubble | XY data points — pass data: [{x, y}, …] |
bubble |
Advanced | Scatter / Bubble | Scatter + per-point size — pass data: [{x, y, r}, …] |
mixed |
Advanced | Mixed | See dedicated <x-wirekit::chart-mixed> wrapper for per-dataset type bindings |
sparkline |
(see component) | Sparklines | See dedicated <x-wirekit::sparkline> wrapper for inline KPI strips |
heatmap |
— | Heatmap | ApexCharts-only |
treemap |
— | Treemap | ApexCharts-only |
boxplot |
— | Boxplot | ApexCharts-only |
candlestick |
— | Candlestick | ApexCharts-only |
range-bar |
— | Range Bar / Timeline | ApexCharts-only. The Timeline demo is this type with plotOptions.bar.horizontal — there is no timeline type of its own |
radial-bar |
— | Radial Bar | ApexCharts-only |
funnel |
— | Funnel | ApexCharts-only |
ApexCharts-only types throw Pushery\ when the Chart.js adapter is active — the exception message includes a "switch to apexcharts" hint. See the Choosing a chart library section above.
Database Example
A real-world example showing the complete flow from database to chart — exactly how you'd build a dashboard in your own app.
Schema::create('monthly_stats', function (Blueprint $table) {
$table->id();
$table->string('month', 10); // 'Jan', 'Feb', ..., 'Dec'
$table->unsignedSmallInteger('year'); // 2025
$table->unsignedInteger('revenue'); // Monthly revenue in EUR
$table->unsignedInteger('costs'); // Monthly costs in EUR
$table->unsignedInteger('visitors'); // Unique visitors
$table->unsignedInteger('desktop_visits');
$table->unsignedInteger('mobile_visits');
$table->unsignedInteger('tablet_visits');
$table->timestamps();
$table->unique(['month', 'year']);
});
class MonthlyStat extends Model
{
protected $fillable = [
'month', 'year', 'revenue', 'costs', 'visitors',
'desktop_visits', 'mobile_visits', 'tablet_visits',
];
public static function forYear(int $year): Collection
{
$order = ['Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'];
return static::where('year', $year)
->get()
->sortBy(fn ($s) => array_search($s->month, $order))
->values();
}
}
class Dashboard extends Component
{
public function render(): View
{
$stats = MonthlyStat::forYear(2025);
return view('livewire.dashboard', [
'labels' => $stats->pluck('month')->toArray(),
'revenue' => $stats->pluck('revenue')->toArray(),
'costs' => $stats->pluck('costs')->toArray(),
'visitors' => $stats->pluck('visitors')->toArray(),
'devices' => [
$stats->sum('desktop_visits'),
$stats->sum('mobile_visits'),
$stats->sum('tablet_visits'),
],
]);
}
}
{{-- Revenue vs Costs --}}
<x-wirekit-chart
type="bar"
:labels="$labels"
:datasets="[
['label' => 'Revenue (EUR)', 'data' => $revenue],
['label' => 'Costs (EUR)', 'data' => $costs],
]"
/>
{{-- Visitor trend --}}
<x-wirekit-chart
type="line"
:labels="$labels"
:datasets="[['label' => 'Visitors', 'data' => $visitors]]"
/>
{{-- Device breakdown --}}
<x-wirekit-chart
type="doughnut"
:labels="['Desktop', 'Mobile', 'Tablet']"
:datasets="[['data' => $devices]]"
height="300px"
/>
That's it — three charts powered by one Eloquent query. WireKit handles all Chart.js configuration, theming, and dark mode automatically.
5. Rendered output
The previews below show what those three Blade snippets render against a representative seeded year (12 months of revenue / costs / visitor data, one row per month, summed for the device split). Real apps swap the inline arrays for the $labels / $revenue / $costs / $visitors / $devices variables the Livewire component passes in step 3 — the data shape is identical.
Custom Options
Pass native Chart.js options to override defaults:
<x-wirekit-chart
type="line"
:labels="$months"
:datasets="[['label' => 'Revenue', 'data' => $values]]"
:options="[
'scales' => ['y' => ['beginAtZero' => false, 'min' => 100]],
'plugins' => ['legend' => ['display' => false]],
]"
/>
User options are deep-merged with WireKit defaults. User values win on conflicts.
With ApexCharts, the labels, the dataset names and the goals of a bar (their name, value and color) reach the legend and the tooltip as text, so a name from your data that holds < or & shows those characters, and markup in it never runs. ApexCharts writes what a formatter returns as HTML. A legend or tooltip formatter you set for every chart through ApexCharts' global options (window.Apex) stays in place, and it has to escape any value from your data it returns.
Colors
A chart draws its series in one of two palettes, chosen with palette:
semantic, the default: the accent, then the danger, success, warning and info colors, then violet, pink and orange. These colors carry meaning elsewhere in WireKit, so a second series reads as "danger" and a third as "success". Use this palette where that meaning is intended, such as profit against loss.categorical: eight pastels from the--color-wk-chart-*tokens, for series that are simply different things, such as sales channels, regions or products. Every pair stays apart for normal vision and under simulated protanopia, deuteranopia and tritanopia, in light and in dark mode.
Which series takes which color
Each series of the categorical palette has a fill and an edge of the same hue. The edge carries the data: it draws a line and its points, and it outlines a bar, a slice and a segment. It stands at 3:1 or more on the page in both modes, so the shape holds the contrast WCAG 1.4.11 asks of a graphic even where the pastel fill does not. The fill colors bars, slices and segments, and the area under a line.
| Series | Fill | Edge | Hue |
|---|---|---|---|
| 1 | --color-wk-chart-1 |
--color-wk-chart-1-edge |
blue |
| 2 | --color-wk-chart-2 |
--color-wk-chart-2-edge |
yellow |
| 3 | --color-wk-chart-3 |
--color-wk-chart-3-edge |
sky |
| 4 | --color-wk-chart-4 |
--color-wk-chart-4-edge |
coral |
| 5 | --color-wk-chart-5 |
--color-wk-chart-5-edge |
sand |
| 6 | --color-wk-chart-6 |
--color-wk-chart-6-edge |
mint |
| 7 | --color-wk-chart-7 |
--color-wk-chart-7-edge |
lavender |
| 8 | --color-wk-chart-8 |
--color-wk-chart-8-edge |
orchid |
The series take the colors in the order of their datasets, and a ninth series starts over at the first. The order keeps the first colors far apart for a chart of few series: the first two and the first four are the most distinct sets of their size. To give one thing the same color in every chart, a channel or a region, keep it at the same position in every chart's datasets.
A label drawn on a fill, the value on an ApexCharts bar, slice or heatmap cell, takes --color-wk-chart-label, which reads at 4.5:1 or more on every fill in both modes. A label beside a line stays in the text color.
What a chart draws beside its subject takes the neutral tone, --color-wk-chart-neutral for a fill and --color-wk-chart-neutral-edge for a line or an outline: the dashed line of a comparison period, the share of tax beside the net amount, the rest of a list as "Other". It carries no hue, so it stands apart from every series without meaning anything, and it follows the same rules as the series, the edge at 3:1 on the page and the label readable on the fill.
Setting the palette for every chart
// config/wirekit.php
'components' => [
'chart' => ['palette' => 'categorical'],
],
A chart's own palette still wins over the config. <x-wirekit:: takes the prop as well. A dataset with its own backgroundColor or borderColor (Chart.js) or color (ApexCharts) keeps it in either palette, see Manual Dataset Colors.
Sequential and diverging scales
Two further sets of tokens color a value rather than a series. --color-wk-chart-seq-1 to --color-wk-chart-seq-7 run from faint to strong in the blue of the first series, for a quantity such as activity or load. --color-wk-chart-div-1 to --color-wk-chart-div-7 run from blue through a neutral middle to orange, for a deviation from a target or an average. Step 1 is the faintest beside the page in both modes, and neighboring steps stay apart under the same three deficiencies.
No chart takes them by itself. Name them with var() where a chart asks for a scale, such as the ranges of an ApexCharts heatmap's color scale, and the adapter resolves them for the current mode. The heatmap page shows one on the sequential scale.
Manual Dataset Colors
Override automatic theming by setting colors directly:
<x-wirekit-chart
type="bar"
:labels="$months"
:datasets="[
[
'label' => 'Revenue',
'data' => $values,
'backgroundColor' => 'rgba(59, 130, 246, 0.5)',
'borderColor' => '#3b82f6',
],
]"
/>
Datasets with manual backgroundColor or borderColor are excluded from automatic dark mode re-theming. If your manual colors need to adapt to dark mode, use CSS variables or handle theme changes in your own JavaScript.
Livewire Integration
The chart root carries wire:ignore, so Livewire's DOM morphing never tears down a drawn chart, and charts are cleaned up during wire:navigate page transitions.
Filtering and re-rendering
When your Livewire component renders new labels or datasets, the chart follows them in place: the labels and series change, the chart stays the same instance, and it animates from the old values to the new ones rather than being built again. An aria-label that describes the data follows with it. A filter above a chart needs nothing extra:
// 1. The filter the reader changes
public string $period = 'week';
public function render(): View
{
// 2. Recompute the data for the chosen period on every render
[$labels, $orders] = $this->ordersFor($this->period);
return view('livewire.reports.orders', [
'labels' => $labels,
'datasets' => [['label' => 'Orders', 'data' => $orders]],
]);
}
<x-wirekit::select label="Period" wire:model.live="period" :options="['week' => 'This week', 'month' => 'This month']" />
<x-wirekit-chart type="bar" :labels="$labels" :datasets="$datasets" aria-label="Orders by period" />
The chart's type and options stay as it first rendered them. A different type is a different chart: give it a wire:key that changes with the type.
Streaming is the other direction: a chart subscribes to a Livewire-dispatched event and appends points as they arrive. Under Chart.js a FIFO cap keeps a long-running page from growing without bound; under ApexCharts the series keeps growing, and the streaming page says how to bound it. The attributes and the two modes are documented under wire:streaming live updates. Use it for a feed that adds points; use the re-render above when the whole series changes.
Loading the chart library on demand
Neither Chart.js nor ApexCharts is bundled by WireKit, so both sit in your own entry chunk — and on a site where most pages carry no chart at all, that is weight every visitor downloads to look at a page without one. The usual answer is to import the library only once a chart actually appears, and for that you need one thing from the markup: a signal that says a chart renders here.
Every rendered chart carries it:
<div data-wk-chart="chartjs" x-data="wirekitChartJs({…})" role="img" aria-label="…">
The value is the identifier of the adapter that rendered this chart — chartjs, apexcharts, or the slug your own adapter returns from name(). It follows the library prop rather than the app default, so a page whose charts use different libraries tells you which is which:
// Import the library only when a chart that needs it is on the page.
const needsApex = document.querySelector('[data-wk-chart="apexcharts"]');
if (needsApex) {
const { default: ApexCharts } = await import('apexcharts');
window.ApexCharts = ApexCharts;
}
A chart that rendered before the import resolved waits for it: it shows nothing until the library is on window, and builds itself the moment it is — no re-initialization on your side. Only a library that is still missing a few seconds after the page has loaded gets the console hint and the advisory panel described under Behavior, and if it arrives even later, the chart replaces the panel.
Three properties of the marker are worth relying on:
- One per chart. The replayable form wraps the chart in a second element, and
chart-mixedrenders through this same component — neither adds a second marker, so counting[data-wk-chart]counts charts. - The value is stable. It is the adapter's library identifier, the same string you write in
config/, and it does not change within a major version. Do not key on the Alpine factory's name instead: that is an internal detail, and renaming it would not be a breaking change, so a selector built on it would quietly stop matching.wirekit. php - The debug placeholder does not carry it. When no adapter is configured and
APP_DEBUGis on, the component renders a placeholder instead of a chart. No chart is there, so no library should be fetched for it — and a loader keyed on this marker will correctly ignore it.
Custom Adapters
Create a class implementing Pushery\. The contract has seven
methods, and a class that leaves one out does not load. The skeleton below binds a library of your
own, here one that draws SVG and takes a list of series:
<?php
namespace App\Charts;
use Pushery\WireKit\Contracts\ChartAdapter;
class LineKitAdapter implements ChartAdapter
{
// 1. The slug the chart root carries as `data-wk-chart`. Keep it stable.
public function name(): string
{
return 'linekit';
}
// 2. Script URLs the page needs; empty when the library comes from npm.
public function scripts(): array
{
return [];
}
// 3. WireKit's labels and datasets in the shape your library reads.
public function normalizeData(string $type, array $labels, array $datasets): array
{
return [
'type' => $type,
'categories' => $labels,
'series' => array_map(fn (array $set): array => [
'name' => $set['label'] ?? null,
'data' => $set['data'] ?? [],
], $datasets),
];
}
// 4. Options merged under the `options` a chart passes.
public function defaultOptions(string $type): array
{
return ['animate' => true];
}
// 5. The Alpine factory your own script registers for these charts.
public function alpineComponent(): string
{
return 'lineKitChart';
}
// 6. `canvas` for a library that draws pixels, `div` for one that draws SVG.
public function rendersTo(): string
{
return 'div';
}
// 7. The types `type=` may name with this adapter.
public function supportedTypes(): array
{
return ['bar', 'line'];
}
}
Set in config:
'charts' => [
'library' => \App\Charts\LineKitAdapter::class,
],
Production
Cache icons for Blade Icons (if using icon components alongside charts):
php artisan icons:cache
License (ApexCharts only)
This section applies only when charts.library is 'apexcharts'. Chart.js is MIT-licensed end-to-end with no per-revenue terms; developers using the default 'chartjs' adapter can skip this section.
Three license tiers
ApexCharts is distributed under one of three licenses. The applicable tier is determined by your organization, not by WireKit. WireKit ships only the adapter glue; the ApexCharts JS library is a separate npm package you install yourself.
| Tier | Who qualifies | Cost |
|---|---|---|
| Community (default) | Personal projects, non-profits, education, and organizations with < $2 million USD annual revenue (consolidated across affiliates and parent/subsidiary entities under common control). | Free |
| Commercial | Organizations with ≥ $2 million USD annual revenue. Includes internal tools, client work, embedded usage. 12-month subscription. | Paid |
| OEM / Redistribution | Required when ApexCharts is embedded into a redistributed product, SDK, platform, or tool. not applicable to WireKit's adapter posture (we do not embed). | Paid (separate) |
Source of truth: apexcharts.com/license. The summary above is informational; you are responsible for verifying your own tier against ApexCharts's then-current legal terms.
Why WireKit does not need an OEM license
The OEM/Redistribution tier kicks in when a vendor embeds ApexCharts into a redistributed product. WireKit does not embed ApexCharts:
- The adapter glue (
src/+Charts/ Apex Charts Adapter. php dist/) maps WireKit's data shape into the ApexCharts options object.wirekit-apex. js - WireKit does not bundle
apexcharts.in anymin. js dist/artifact. - WireKit does not include ApexCharts source in
composer.jsonorpackage.json. - You install ApexCharts yourself via
npm install apexcharts.
Same posture WireKit holds for Chart.js. The adapter glue is MIT (WireKit's license); the JS library is your responsibility to license correctly.
Recording your tier in config/wirekit.php
'charts' => [
'library' => 'apexcharts',
'apex_license' => 'commercial', // 'community' | 'commercial' | 'oem'
],
apex_license is informational — WireKit gates nothing on its value. It serves two purposes:
- Audit trail — a single source of truth records which tier you've adopted alongside the rest of your config.
- Doctor reminder —
php artisan wirekit:doctorreports the value back to you. Which severity it reports it at depends on the value, and there are three outcomes rather than two:
apex_license |
wirekit:doctor reports |
Under --fail-on=warning |
|---|---|---|
'commercial' or 'oem' |
a pass, naming the tier back | green |
'community' |
an info line — the reminder still prints on every run | green |
| unset, or a value that is none of the three | a warning | red until a recognized tier is recorded |
The split between the middle row and the last one is what keeps --fail-on=warning usable as a build gate, and it is deliberate. The community line is true on every run of a correctly configured install and will never stop being true, so counted as a warning it would hold the exit code at 1 forever — and a check that is permanently red is one a team learns to pass with || true, taking the config drift the flag exists to catch with it. An undeclared tier is the opposite shape: recording one is a single entry in config/, after which the warning is gone for good and a 'community' value settles into the info line. The same pair is documented from the flag's side in the CLI Reference, under wirekit:verify.
Doctor output examples
These are the lines wirekit:doctor prints, one per outcome. The marker in front of each is the severity: ✓ for a pass, i for info, ! for a warning.
'commercial' or 'oem' — the tier is named back and nothing else is said:
✓ ApexCharts license tier declared: commercial
'community' — info, so it does not move the exit code:
i Declared tier: community. This reminder stays — the $2M USD revenue threshold for the ApexCharts Community License is a continuing condition, not an install step. Purchase a Commercial License at https://apexcharts.com/license/ once you pass it.
Unset — a warning, and the one line that tells you which entry to make:
! ApexCharts is non-MIT. Confirm your organization is below the $2M USD revenue threshold for the Community License, or purchase a Commercial License at https://apexcharts.com/license/. Record your tier via `charts.apex_license` in config/wirekit.php (values: community / commercial / oem).
Recorded but unrecognized — a warning that names the value back, so a typo is visible without opening the config. It counts as undeclared until it matches one of the three:
! Unrecognized ApexCharts license tier `comercial` in `charts.apex_license`. Accepted values: community / commercial / oem. Until it matches one of those it is treated as undeclared.
Licensing Pitfalls
- Don't bundle
apexcharts.into a deployment artifact you redistribute (e.g. an admin-panel package you ship to multiple clients). That triggers the OEM/Redistribution tier — separate from the per-organization Commercial license.min. js - Don't quote a stale revenue threshold figure to your team. ApexCharts's terms can change; always link to apexcharts.com/license rather than hard-coding the number in your README.
- Don't conflate Community License with public-domain. ApexCharts retains copyright; you're using it under license terms, not as a freely modifiable codebase.
Behavior
- Charts disabled (default):
Runtimewith config instructions.Exception - Chart.js not installed:
console.errorin the browser with the npm install instructions, PLUS a visible advisory panel where the chart would have been. - ApexCharts not installed (adapter bundle loaded):
console.errorPLUS a visible in-DOM advisory panel inside the chart container — surfaces the install command, the license reminder, and a link toapexcharts.so the developer can act without opening DevTools first.com/ license - Either library loaded after the chart mounted: nothing at all. Both adapters keep looking, and the hint and the panel above wait until the page has loaded and a few more seconds have passed — a library loaded on demand is picked up instead.
- Many charts on one page: each chart is built in a task of its own, in the order the charts start, so the page paints the charts drawn so far and answers clicks and keys between two of them. A browser test that waits for one chart's drawing waits for that chart, not for every chart on the page.
- A chart of whole numbers: while every value on the value axis is a whole number, the axis steps in whole numbers, so seven days without a visit read 0, 1, 2 rather than 0, 0.5, 1, 1.5, 2. The x-axis of a scatter or a bubble chart does the same where every point stands at a whole number on it, so ratings from 1 to 5 stand at 1, 2, 3, 4 and 5. Under ApexCharts, points between whole numbers step the x-axis on the tenths or hundredths they stand on, and its labels carry the decimals of the steps, so weights from 0.5 to 3 read 0.5, 1.0, 1.5 and on, where no label stands twice; a point with more than two decimals leaves the axis as ApexCharts divides it. ApexCharts does it through
forceNiceScaleon the value axis and through the number of ticks on the x-axis, Chart.js throughticks., which the chart reads again with each update of its data. Steps you choose stay yours: in ApexCharts aprecision: 0 forceNiceScale,tickAmountorstepSizeof your own, a logarithmic axis, aminormaxthat is not a whole number, or a second value axis, and on the x-axis anytickAmount,stepSize,min,maxordecimalsInFloat; in Chart.js aticks.precision,ticks.stepSizeorticks.count, or a scale type other thanlinear. - Unknown adapter:
Invalidlisting available adapters.Argument Exception - Custom adapter not implementing interface:
Invalid.Argument Exception
Troubleshooting: blank chart with no console error
When <x-wirekit-chart library="apexcharts"> (or library="chartjs") renders an empty container with no visible advisory panel and no console.error, the most likely cause is the adapter bundle itself is not loaded — Alpine sees x-data="wirekit referencing a factory function that was never registered. Check the browser's network panel for a 404 on dist/ (when using ApexCharts) or dist/wirekit.js / dist/ (when using Chart.js). The visible-fallback panel only renders when the WireKit adapter bundle is loaded but the underlying chart library (window. / window.Chart) is still missing a few seconds after the page has loaded.
The library prop changes the Alpine factory name the chart's x-data references. When the per-instance library differs from your app's default (config('wirekit.), you must load both the corresponding adapter bundle and the underlying chart library. Mixing libraries on the same page is supported but doubles the JS payload — verify against your bundle budget before shipping.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type |
string |
'bar' |
Chart type: bar, line, area, pie, doughnut, radar, polarArea, scatter and bubble under either library, and the ApexCharts-only types the table under Chart Types lists |
labels |
array |
[] |
X-axis labels |
datasets |
array |
[] |
Data arrays with label and data keys. A dataset without a label is named "Series 1", "Series 2" and so on in the application's language. The single dataset of a pie, doughnut or polarArea chart stays unnamed, because its slices carry the names. urls, one address per point, and url on a point object make points links, see Linking data points |
options |
array |
[] |
Native options of the active library, Chart.js or ApexCharts, deep-merged with WireKit's defaults |
height |
string |
'380px' |
Container height |
wireStream |
?string |
null |
Livewire event name to subscribe to for real-time appending. When set, the Alpine factory listens for the event and pipes each incoming point payload into the chart through the library's imperative API — Chart.js pushes onto data.datasets[i].data, ApexCharts calls appendData(). null renders a normal chart with no streaming behavior. Setting it also auto-enables replayable. Worked examples: Streaming |
wireStreamMode |
string |
'strict' |
'strict' bounds each dataset by wireStreamCap, and 'stream' lets the series grow without a bound. Chart.js drops the oldest point on each tick (FIFO); ApexCharts, on a chart whose window xaxis.range bounds, lets a series grow to half again the cap and cuts it back outside that window, see Streaming. |
wireStreamCap |
int |
100 |
The most points a dataset keeps under 'strict': this many with Chart.js, between this many and half again as many with ApexCharts on a chart with xaxis.range. Ignored when wireStreamMode is 'stream'. |
annotations |
array |
[] |
Annotation specs threaded into the chart options. ApexCharts maps them onto options.annotations. Chart.js needs chartjs-plugin-annotation installed; without it the chart still renders and the annotations are skipped with a console.warn rather than an error, so a missing plugin looks like annotations that silently do nothing. Worked examples: Annotations |
inline |
bool |
false |
Render the wrapper as <span style="display: inline-block"> (and the SVG mount as <span>) instead of the default <div>. Required to place a chart inside a <p> — HTML5's parser auto-closes a <p> the moment it encounters a <div> descendant. <x-wirekit::sparkline inline> flips this automatically; pass it directly on <x-wirekit-chart> for inline-chart usage in narrative prose. |
replayable |
bool |
false |
Emits data-replayable="true" on the chart root, the hook a replay button of your own can key on to run the entrance animation again (bar-grow, line-trace, slice-sweep); the WireKit docs use it for theirs. Set whenever wireStream is bound, since replaying a streaming chart restarts its ticker. Nothing else about the chart changes. |
library |
?string |
null |
Per-instance chart-library override. Accepts the same values as config('wirekit.charts.library') — the built-in keys chartjs / apexcharts, or a fully qualified class name implementing ChartAdapter. When null (default), the chart uses whatever the global wirekit.charts.library config resolves to. When set, this chart instance binds to the named library regardless of the app default; two charts on the same page can use different libraries. |
valueDecimals |
?int |
null |
ApexCharts only. Rounds raw float y-values in the tooltip, and in the cells of a treemap that sets dataLabels.wkShowValue, to N decimal places. Without it, a value like 50.523626895740676 prints in full; valueDecimals="2" shows 50.52. null (default) keeps the raw value. A dataset's own decimals take its place for that series |
valuePrefix |
?string |
null |
ApexCharts only. Text prepended to each formatted tooltip value, and to a treemap cell's value (e.g. "€", "$"). The y-axis keeps the bare number, and its title names the unit (Tooltip value formatting). |
valueSuffix |
?string |
null |
ApexCharts only. Text appended to each formatted tooltip value, and to a treemap cell's value (e.g. " ms", "%"). Combine with valueDecimals for "50.52 ms". The y-axis keeps the bare number, and its title names the unit (Tooltip value formatting). |
valueGrouping |
bool |
true |
ApexCharts only. Groups the thousands of the values in the tooltip, in a treemap's cells and on the y-axis the chart labels itself, the locale's way (278.984,46 in German). false writes them ungrouped. |
tooltipExtras |
array |
[] |
Further values the tooltip names for each point without a series of their own: ['label' => 'Receipts', 'data' => [48, 37]], or a list of them, each with an optional decimals, prefix and suffix. See A further value in the tooltip |
palette |
?string |
null |
The colors the series take: semantic or categorical, see Colors. null takes config('wirekit.components.chart.palette'), which ships as semantic. |
table |
bool|string|null |
null |
The chart's data as a table under it: disclosure (or true) behind a summary every reader can open, screen-reader out of sight. Not on an inline chart. See Offer the data as a table. |
label-tips |
bool |
true |
A shortened axis label shows its full text in a tooltip under the pointer and on a touch (ApexCharts). See Long axis labels. |
Accessibility
Charts are a well-known accessibility challenge: Chart.js draws the data on a <canvas> and ApexCharts in an SVG, and neither tells a screen reader what the data says. WireKit recommends the following patterns:
1. Label the chart as an image
Pass a descriptive aria-label to the chart itself. The component already renders
role="img" on its root, so the label lands on the element that carries the role:
<x-wirekit-chart
type="line"
:labels="$months"
:datasets="$datasets"
aria-label="Monthly revenue chart, January to December 2025. Peaks at €42,000 in December."
/>
Do not wrap the chart in a second role="img" container. Two nested images are one
image to a screen reader: the outer element wins, and the chart's own role and name are
dropped from the accessibility tree.
Without an aria-label the chart falls back to the single word "Chart", which tells a
reader that something graphical is here and nothing about the data in it. With
APP_DEBUG=true the component writes a log line pointing at the chart that needs one. A chart
named by aria-labelledby, or hidden with aria-hidden="true" because the figure it draws is
already text beside it, needs no label and gets no such line.
The aria-label should summarize what the data shows, including:
- The metric (e.g. "Monthly revenue")
- The time range or categories
- Key takeaways (peaks, trends, comparisons)
This is the minimum A11y contract — every chart should have one.
2. Offer the data as a table
table renders the chart's data as a native table under it: one row per label, one column per dataset, each value written as the tooltip writes it, with value-decimals, value-prefix and value-suffix, and a missing value named rather than left empty. table="disclosure", or the attribute on its own, puts the table behind a "Chart data" summary that every reader can open, a keyboard included. table="screen-reader" keeps it out of sight, where a screen reader reads it after the chart's name.
Its cells keep a compact padding, so the table of a week of series fits a chart in half a card,
and its frame scrolls only a table wider than the chart. While it does, a shadow stands at each
edge the table continues past, as on a table that scrolls sideways, so a
table cut off at a column does not read as the whole table. The summary stands at least 24 px
tall, the minimum target size, whatever line height the page around it sets.
Chart data
Chart data
{{-- 1. The table behind a summary, for every reader --}}
<x-wirekit-chart type="bar" :labels="$months" :datasets="$datasets" table aria-label="Monthly revenue for 2025" />
{{-- 2. The table for a screen reader only --}}
<x-wirekit-chart type="bar" :labels="$months" :datasets="$datasets" table="screen-reader" aria-label="Monthly revenue for 2025" />
The table takes the chart's name as its caption, so a reader who reaches it on its own knows which chart it belongs to, and its labels stand as rows whatever the chart's orientation: a horizontal bar chart reads as a vertical one does. It renders outside the chart's wire:ignore, so a Livewire update reaches it with the data; the points wire-stream adds in the browser are not in it. An inline chart stands in a sentence, which has no room for a table, and reports the prop. <x-wirekit:: takes it as well.
Benefits:
- Screen readers can navigate cell-by-cell with arrow keys.
- Keyboard users open the summary and read the exact values.
- Progressive enhancement — the table is in the page before any script runs.
3. Do not rely on color alone
Chart.js colors encode categories (e.g. different datasets). Meet WCAG 1.4.1 ("Use of Color") by also distinguishing datasets via:
- Different line styles (
borderDash: [5, 5]) on line charts - Different point shapes (
pointStyle: 'triangle' | 'rect' | 'circle') - Patterns on bar fills (via Chart.js plugins like patternomaly)
The categorical palette keeps every pair of series apart under the three common color vision deficiencies. That helps a reader tell the series apart, and it is no substitute for a second cue: a legend, a label at the end of each line, or a pattern.
4. Include the summary in surrounding text
The best chart A11y pattern is one the user doesn't even need: describe the trend in the paragraph before or after the chart. Screen readers read content linearly — a sentence like "Revenue grew 34% year-over-year, peaking in December" reaches more users than any aria-label.
References
Keyboard Interaction
A chart responds to no key itself. A chart whose points lead somewhere lists their links after itself, and Tab reaches each of them; the list shows under the chart while one of them has the focus, see Linking data points.
ApexCharts 7 brings a keyboard navigation of its own over the data points. The component leaves it
switched off: the drawing is hidden from assistive technology, and a tab stop inside it would take
the keyboard where a screen reader is told not to go. The data stays reachable through the text
alternative described above, and through the table table renders under the chart.
Pitfalls
- Don't render a chart without a text alternative. WCAG 1.1.1 (Non-text Content) — give it its data as a table with
table, or pair the chart with a<x-wirekit::summarizing the trend, or adata-list> <x-wirekit::highlighting the headline number.stat> - Don't give a chart a
wire:keythat changes with its data. A changing key replaces the chart and replays its entrance animation on every update. The chart follows new labels and datasets by itself, see Filtering and re-rendering.
Design Tokens
Charts read their palette from WireKit's CSS variables. Override these tokens at :root {} (or inside a .dark { … } block) and every mounted chart picks up the change automatically.
| Token | Used for |
|---|---|
--color-wk-accent |
First dataset color (primary series) |
--color-wk-success |
Positive / "good" series |
--color-wk-warning |
Warning series |
--color-wk-danger |
Negative / "bad" series |
--color-wk-info |
Informational series (rare) |
--color-wk-text |
Legend label text |
--color-wk-text-muted |
Axis-tick labels |
--color-wk-border |
Grid line + axis line color |
--color-wk-surface |
The surface every series is checked against: the page, or the card or panel that holds the chart |
--color-wk-chart-1 to --color-wk-chart-8, each with an -edge |
The series of the categorical palette, fill and edge |
--color-wk-chart-label |
A label on a fill in the categorical palette |
--font-wk-sans |
Legend + axis-tick font family |
The chart paints no background of its own: it shows the surface it stands on, the page or the card or panel that holds it.
In the semantic palette every series holds 3:1 against that surface, the contrast WCAG 1.4.11 asks of a graphic a reader needs to understand. Where a token is gray, or falls under that, the chart draws the series in its own shade of the same hue instead: a 600 shade in light mode, a 200 shade in dark mode. The token itself stays as it is for everything else that reads it. With ApexCharts a line is drawn opaque, because the 3:1 holds for the color as it is and ApexCharts would draw a line at 85% of it. A fill.opacity of your own wins, and its contrast is then yours to keep. The sixth to eighth series have no token and use violet, pink and orange in the same two shades. The categorical palette takes its tokens as they are, as their edges hold the 3:1 themselves.
Dark mode works automatically — when the .dark class toggles on <html>, a Mutation re-reads all CSS variables and updates the chart instantly (grid lines, tick labels, legend text, and dataset colors). No page reload needed.
A chart inside a .dark or .light subtree draws in that subtree's theme: the mode and every token come from the nearest scope, so a light panel on a dark page keeps a light chart. The chart reads its scope when it mounts and whenever the page's own theme changes; switching a subtree's class later does not repaint it.