Charts
ApexCharts
A chart drawn by ApexCharts, configured with the library's own options. It loads the library on demand, follows the light and dark color scheme and redraws when Livewire sends new options.
Nothing to show
Nothing to show
A spinner shows while the library loads, then a bar chart with three bars takes its place. options is the ApexCharts configuration, as a PHP array.
Updated by Livewire #
After addMonth() the chart already on the page is updated with the new options and shows a fourth bar. Any option can change this way, including the series and the chart type.
Nothing to show
Nothing to show
Options written in JavaScript #
data-options is a JavaScript object merged over options, for what a PHP array cannot carry, such as formatter functions. Here the bars are red and the axis reads 30 un. It also works alone, with no options at all.
Nothing to show
Options from an endpoint #
tk:fetchable requests the URL and draws the JSON it answers, which is the ApexCharts configuration. Calling its update('/reports/sales?year=2025') requests again and updates the same chart.
Nothing to show
Nothing to show
Nothing to show
Chart types #
chart.type picks the kind of chart: line, area, bar, donut, radialBar... Pie-like charts take a flat series and labels.
Nothing to show
Nothing to show
Nothing to show
Rendering from data #
One chart per record, side by side, each with its own label and a wire:key.
Nothing to show
Nothing to show
Nothing to show
Events #
ApexCharts' own events, such as dataPointSelection, go in chart.events through data-options: here a click on a bar calls a Livewire action. rendered fires on the tag each time the chart is drawn.
Nothing to show
Nothing to show
Customization #
Classes go to the chart element; loadable: reaches the wrapper and loadable:loading: the spinner.
Nothing to show
Nothing to show
Reference
tk:apexcharts
| Prop | Type | Default | Description |
|---|---|---|---|
options |
array | null |
The ApexCharts configuration: chart, series, xaxis... |
label |
string | Chart |
The accessible name of the chart, translated. |
description |
string | slot | null |
A text alternative read by screen readers, linked with aria-describedby: what the chart shows ("Sales grew 20% in March"). |
data-options is an attribute, not a prop: a JavaScript expression that returns an object of options.
tk:apexcharts is tk:chart with library="apexcharts": label, description and every other attribute are passed to it.
Events
| Event | Detail | When |
|---|---|---|
rendered |
{ chart }, the ApexCharts instance |
The chart was drawn: the first time, on each update of the options and when the color scheme changes. |
started |
The library started loading. Not fired with loadable:silent. |
|
completed |
The library is loaded; the chart is drawn right after. | |
failed |
The library could not be loaded, or ApexCharts threw while creating the chart. |
Prefixes
| Prefix | Goes to |
|---|---|
loadable: |
The wrapper around the chart, the spinner and the error. loadable:silent hides the spinner. |
loadable:loading: |
The spinner shown while the library loads. |
loadable:error: |
The error message. |
Events
rendered is dispatched on the chart element, the one the tag's attributes go to, and does not bubble: listen on the tag itself. started, completed and failed are dispatched on the wrapper around it and do not bubble either, so they are listened to with the loadable: prefix.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on the tag go to the chart element. To reach the elements around it, prefix the attribute (listed in the Reference above).
Nothing to show
The size of the chart is set in the options (chart.height, chart.width).
Accessibility
The chart element has role="figure" and an aria-label: the label prop, or "Chart" translated. Give each chart a label that says what it shows and a description with its main takeaway. The spinner and the error message are role="status" regions. Keyboard interaction inside the chart is the library's own.
Behavior notes
- The library is loaded from
https://cdn.jsdelivr.net/npm/apexcharts@5by the first chart on the page, once for all of them. Whenwindow.ApexChartsalready exists, as when the app bundles the library, nothing is requested. - Without
theme.modein the options the chart follows thedarkclass of<html>: it is drawn in the matching mode, with a transparent background, and drawn again when the class changes. Settingtheme.modefixes the mode and stops that. data-optionsis merged deeply overoptions: nested objects are combined key by key ({ chart: { type: 'area' } }keeps the PHPchart.height), while arrays and other values are taken whole fromdata-options.- A Livewire update that changes
optionsupdates the same ApexCharts instance, merging the new options into it. When a top-level key of the previous options is missing from the new ones (atitle,annotations), the chart is destroyed and created again, so what the server no longer sends disappears. A color scheme change also destroys it and creates another. Take the instance from the latestrenderedevent, or callgetChart(), which Alpine expressions written on the tag can use. optionsthat start empty and are filled by a later Livewire update draw the chart at that moment.- With neither
optionsnordata-optionsnothing is drawn, and no error shows. - When the library cannot be loaded, or ApexCharts throws while creating the chart (an
xaxisthat is not an array, for instance), the error message takes the place of the chart andfailedfires. A later Livewire update with valid options does not draw it again: the page has to be reloaded. - Options ApexCharts rejects only while drawing, such as a
seriesthat is not an array, leave the chart blank with the error in the browser console only; no message shows,faileddoes not fire andrenderedstill does.
Related
library prop, when it is decided at runtime.
Chart.js
the same tag for other chart libraries, each with its own options format.
ECharts
the same tag for other chart libraries, each with its own options format.
Frappe Charts
the same tag for other chart libraries, each with its own options format.
Fetchable
loads data from a URL and, with chart="apexcharts", draws it.