EN
Getting started
79 · Charts

Charts

A chart drawn with ApexCharts. The options array is the PHP equivalent of the ApexCharts configuration; in the dark theme the axis, grid and tooltip colors adapt automatically, and the chart is repainted when the theme changes.

PRO acun:chart
01

Basic usage

Give the chart type with chart.type, the data with series and the axis labels with xaxis.categories. The ApexCharts toolbar is hidden by default and the chart uses the page's font.

LIVE EXAMPLE
<acun:chart :options="[
    'chart' => ['type' => 'area'],
    'series' => [['name' => 'Orders', 'data' => [2810, 2944, 3012, 2890, 3240, 3106]]],
    'xaxis' => ['categories' => ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']],
    'colors' => ['primary'],
    'stroke' => ['curve' => 'smooth', 'width' => 3],
    'fill' => ['type' => 'gradient', 'gradient' => ['opacityFrom' => 0.4, 'opacityTo' => 0.05]],
    'dataLabels' => ['enabled' => false],
]" />
PropValues
optionsApexCharts configuration
colorsSeries colors: palette names (primary, secondary, success, danger, warning, info, dark) or color values; if omitted, the palette order
02

Line and bar

Other ApexCharts types such as line and bar are drawn with the same structure. Add multiple series to the series array; each series takes its color from its position in colors.

LIVE EXAMPLE
<acun:chart :height="300" :options="[
    'chart' => ['type' => 'line'],
    'series' => [['name' => 'Web', 'data' => [96, 110, 104, 120, 118, 112]], ['name' => 'Mobile', 'data' => [40, 44, 52, 49, 58, 61]]],
    'xaxis' => ['categories' => ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']],
    'colors' => ['primary', 'info'],
    'stroke' => ['width' => 3],
]" />
<acun:chart :height="300" :options="[
    'chart' => ['type' => 'bar'],
    'series' => [['name' => 'Orders', 'data' => [412, 388, 295, 176, 142]]],
    'xaxis' => ['categories' => ['Istanbul', 'Ankara', 'Izmir', 'Bursa', 'Antalya']],
    'colors' => ['primary'],
    'plotOptions' => ['bar' => ['borderRadius' => 4, 'columnWidth' => '45%']],
    'dataLabels' => ['enabled' => false],
]" />
PropValues
chart.typearea | line | bar | donut | pie | radialBar …
03

Donut chart

In donut and pie charts, series is a flat array of numbers and the slice names are given with labels. Use #e5e7eb for the remaining or empty slice: in the dark theme this color is automatically turned into dark gray (#474747).

LIVE EXAMPLE
<acun:chart :height="300" :options="[
    'chart' => ['type' => 'donut'],
    'series' => [3106, 214, 96],
    'labels' => ['Delivered', 'In transit', 'Returned'],
    'colors' => ['success', 'warning', 'danger'],
    'legend' => ['position' => 'bottom'],
]" />
<acun:chart :height="300" :options="[
    'chart' => ['type' => 'donut'],
    'series' => [74, 26],
    'labels' => ['Completed', 'Remaining'],
    'colors' => ['primary', '#e5e7eb'],
    'legend' => ['position' => 'bottom'],
    'dataLabels' => ['enabled' => false],
]" />
PropValues
seriesArray of numbers
labelsSlice names
#e5e7ebBecomes #474747 in the dark theme
04

Height

Give the height in pixels with height; the default is 280. Until the chart is drawn, the container reserves this height so the page does not shift. For small charts in cards, hide the axes with the ApexCharts sparkline option.

LIVE EXAMPLE
<acun:card>
    <p class="text-sm text-gray-500 dark:text-zinc-400">Weekly orders</p>
    <p class="text-2xl font-semibold text-gray-900 dark:text-zinc-100">742</p>
    <acun:chart :height="80" :options="[
        'chart' => ['type' => 'area', 'sparkline' => ['enabled' => true]],
        'series' => [['name' => 'Orders', 'data' => [96, 104, 99, 118, 112, 107, 106]]],
        'colors' => ['success'],
        'stroke' => ['curve' => 'smooth', 'width' => 2],
    ]" />
</acun:card>
PropValues
heightPixels (default 280)
05

Installation

ApexCharts is not included in the package; install it in your application and register it with registerChart through the PRO JS entry @acunsoft/acun-ui-pro (the Vite alias from the CSS, JavaScript and build guide). Because the chart is drawn inside wire:ignore, it is not recreated on Livewire updates.

JS
import ApexCharts from 'apexcharts';
import { registerChart } from '@acunsoft/acun-ui-pro';

document.addEventListener('livewire:init', () => registerChart(Alpine, ApexCharts));
API

Props and slots

The values the component accepts.

PropDefaultDescription
options[]ApexCharts configuration (chart, series, xaxis, colors…)
height280Chart height (pixels); the placeholder also opens at this height
options.chart.toolbar.showfalseApexCharts toolbar; shown with true
options.chart.fontFamilyinheritUses the page's font
Acun UI · ChartsDetailed usage and examples