Skip to content

Chart API

The Chart class is the fluent builder behind LiveCharts::line(), LiveCharts::bar(), and friends. Every method returns $this for chaining.

MethodSignatureDescription
type()type(string $type): selfSet the chart type (line, bar, pie, …).
engine()engine(string $name): selfSelect the rendering engine (optional — auto-routed if omitted).

Calling ->engine() is optional. When omitted, EngineFactory::engineForType() selects the best available engine for the chart type: apex-only types → apexcharts, chartjs-only types → chartjs, shared types → apexcharts.

LiveCharts::make()->type('bar')->engine('chartjs'); // explicit
LiveCharts::bar()->labels(['A'])->dataset('S', [1]); // engine auto-selected
MethodSignatureDescription
labels()labels(array $labels): selfX-axis labels (or pie slice labels).
dataset()dataset(string $name, array $data): selfAppend a single dataset.
datasets()datasets(array $datasets): selfReplace all datasets at once.
colors()colors(array $hexes): selfOverride the colour palette.
LiveCharts::line()
->labels(['Jan', 'Feb', 'Mar'])
->dataset('Revenue', [10, 20, 30])
->colors(['#10B981']);
MethodSignatureDescription
title()title(string $text): selfChart title rendered by the engine.
subtitle()subtitle(string $text): selfOptional subtitle.
theme()theme(string $mode): selfauto, light, or dark.
options()options(array $options): selfEngine-native options (deep-merged).
MethodSignatureDescription
poll()poll(): selfEnable polling at the configured default interval.
pollEvery()pollEvery(int $seconds): selfEnable polling at a custom interval.
onDataPointClick()onDataPointClick(string $event): selfDispatch a Livewire event on click.
LiveCharts::bar()
->pollEvery(15)
->onDataPointClick('drilldown');

Chart::TYPES exposes the canonical list of supported types. The make:chart command derives its --type option list from this constant — keep the two in sync if you fork.

When extending Chart directly, every fluent setter has a corresponding overridable method:

FluentClass-based
->type('bar')protected string $type = 'bar';
->engine('chartjs')protected string $engine = 'chartjs';
->labels([...])public function labels(): array
->dataset(...)public function datasets(): array
->options([...])public function options(): array

See Class-Based Charts for the full pattern.