v0.0.2
Demos (demo panel, opens in a new tab)

Charts

Draws area, line, bar and donut charts with ApexCharts.

zb:chart zubazar/ui-pro

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

Basic usage: view
BLADE

Set the type with chart.type, the data with series and the axis labels with xaxis.categories.

blade
<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],
]" />
PropValues
optionsApexCharts configuration
colorsSeries colors: palette names (primary, secondary, success, danger, warning, info, dark) or color values; if omitted, the palette order

Line and bar

Line and bar: view
BLADE

Draw line and bar charts with the same structure; each series takes its colour from its place in colors.

blade
<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],
]" />
PropValues
chart.typearea | line | bar | donut | pie | radialBar …

Donut chart

Donut chart: view
BLADE

In donut and pie charts series is a plain array of numbers and the slice names go in labels.

blade
<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],
]" />
PropValues
seriesArray of numbers
labelsSlice names
#e5e7ebBecomes #474747 in dark mode

Height

Height: view
BLADE

Set the height in pixels with height (default 280); use sparkline for small charts in cards.

blade
<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>
PropValues
heightPixels (default 280)

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
format—nullThe 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…)
heightnumber280Chart height (pixels); the placeholder also opens at this height
options.chart.toolbar.showbooleanfalseApexCharts toolbar; shown with true
options.chart.fontFamily—inheritUses the page's font

Installation

Install ApexCharts and register it in resources/js/app.js.

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

Events, hooks and details
  • The options array 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.
  • lazyLibrary downloads 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 #e5e7eb for an empty or remaining slice; in the dark theme it turns dark grey (#474747).
Zubazar UI · ZubazarDesigned for people.