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.

Blade

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.

3 bars
Blade

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.

Blade

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.

Blade

Chart types #

chart.type picks the kind of chart: line, area, bar, donut, radialBar... Pie-like charts take a flat series and labels.

Blade

Rendering from data #

One chart per record, side by side, each with its own label and a wire:key.

Europe
Americas
Blade

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.

Click a bar. Selected: —
Blade

Customization #

Classes go to the chart element; loadable: reaches the wrapper and loadable:loading: the spinner.

Blade

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:

blade

Calling a Livewire action:

blade

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).

blade

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@5 by the first chart on the page, once for all of them. When window.ApexCharts already exists, as when the app bundles the library, nothing is requested.
  • Without theme.mode in the options the chart follows the dark class of <html>: it is drawn in the matching mode, with a transparent background, and drawn again when the class changes. Setting theme.mode fixes the mode and stops that.
  • data-options is merged deeply over options: nested objects are combined key by key ({ chart: { type: 'area' } } keeps the PHP chart.height), while arrays and other values are taken whole from data-options.
  • A Livewire update that changes options updates 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 (a title, 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 latest rendered event, or call getChart(), which Alpine expressions written on the tag can use.
  • options that start empty and are filled by a later Livewire update draw the chart at that moment.
  • With neither options nor data-options nothing is drawn, and no error shows.
  • When the library cannot be loaded, or ApexCharts throws while creating the chart (an xaxis that is not an array, for instance), the error message takes the place of the chart and failed fires. 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 series that is not an array, leave the chart blank with the error in the browser console only; no message shows, failed does not fire and rendered still does.