Charts
Draws area, line, bar and donut charts with ApexCharts.
zb:chart zubazar/ui-pro
Needs a JavaScript library registration: see Setup.
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Basic usage
Set the type with chart.type, the data with series and the axis labels with xaxis.categories.
<zb: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],
]" />
| Prop | Values |
|---|---|
options | ApexCharts configuration |
colors | Series colors: palette names (primary, secondary, success, danger, warning, info, dark) or color values; if omitted, the palette order |
Line and bar
Draw line and bar charts with the same structure; each series takes its colour from its place in colors.
<zb: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],
]" />
<zb: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],
]" />
| Prop | Values |
|---|---|
chart.type | area | line | bar | donut | pie | radialBar … |
Donut chart
In donut and pie charts series is a plain array of numbers and the slice names go in labels.
<zb:chart :height="300" :options="[
'chart' => ['type' => 'donut'],
'series' => [3106, 214, 96],
'labels' => ['Delivered', 'In transit', 'Returned'],
'colors' => ['success', 'warning', 'danger'],
'legend' => ['position' => 'bottom'],
]" />
<zb:chart :height="300" :options="[
'chart' => ['type' => 'donut'],
'series' => [74, 26],
'labels' => ['Completed', 'Remaining'],
'colors' => ['primary', '#e5e7eb'],
'legend' => ['position' => 'bottom'],
'dataLabels' => ['enabled' => false],
]" />
| Prop | Values |
|---|---|
series | Array of numbers |
labels | Slice names |
#e5e7eb | Becomes #474747 in dark mode |
Height
Set the height in pixels with height (default 280); use sparkline for small charts in cards.
<zb:card>
<p class="text-sm text-muted">Weekly orders</p>
<p class="text-2xl font-semibold text-ink">742</p>
<zb: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],
]" />
</zb:card>
| Prop | Values |
|---|---|
height | Pixels (default 280) |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
format | — | null | The values' format in the page's language (axis, tooltip, data labels, table): number · compact · currency (currency="TRY") · percent, or Intl.NumberFormat options |
options | — | [] | ApexCharts configuration (chart, series, xaxis, colors…) |
height | number | 280 | Chart height (pixels); the placeholder also opens at this height |
options.chart.toolbar.show | boolean | false | ApexCharts toolbar; shown with true |
options.chart.fontFamily | — | inherit | Uses the page's font |
Installation
Install ApexCharts and register it in resources/js/app.js.
// npm install apexcharts
// resources/js/app.js
document.addEventListener('livewire:init', () => {
const { lazyLibrary, registerChart } = window.ZubazarUI.pro;
registerChart(window.Alpine, lazyLibrary(() => import('apexcharts')));
});
Developer notes
- The
optionsarray is the PHP form of the ApexCharts configuration. - In the dark theme the axis, grid and tooltip colours adapt on their own; the chart repaints when the theme changes.
lazyLibrarydownloads ApexCharts only on a page with a chart; you can also pass the library directly:registerChart(window.Alpine, ApexCharts).- The chart is drawn in
wire:ignore; Livewire updates do not rebuild it. - Until the chart is drawn, the container keeps the
height, so the page does not jump. - Use
#e5e7ebfor an empty or remaining slice; in the dark theme it turns dark grey (#474747).