Chart API
The Chart class is the fluent builder behind LiveCharts::line(), LiveCharts::bar(), and friends. Every method returns $this for chaining.
Type & engine
Section titled “Type & engine”| Method | Signature | Description |
|---|---|---|
type() | type(string $type): self | Set the chart type (line, bar, pie, …). |
engine() | engine(string $name): self | Select 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'); // explicitLiveCharts::bar()->labels(['A'])->dataset('S', [1]); // engine auto-selected| Method | Signature | Description |
|---|---|---|
labels() | labels(array $labels): self | X-axis labels (or pie slice labels). |
dataset() | dataset(string $name, array $data): self | Append a single dataset. |
datasets() | datasets(array $datasets): self | Replace all datasets at once. |
colors() | colors(array $hexes): self | Override the colour palette. |
LiveCharts::line() ->labels(['Jan', 'Feb', 'Mar']) ->dataset('Revenue', [10, 20, 30]) ->colors(['#10B981']);Presentation
Section titled “Presentation”| Method | Signature | Description |
|---|---|---|
title() | title(string $text): self | Chart title rendered by the engine. |
subtitle() | subtitle(string $text): self | Optional subtitle. |
theme() | theme(string $mode): self | auto, light, or dark. |
options() | options(array $options): self | Engine-native options (deep-merged). |
Reactivity
Section titled “Reactivity”| Method | Signature | Description |
|---|---|---|
poll() | poll(): self | Enable polling at the configured default interval. |
pollEvery() | pollEvery(int $seconds): self | Enable polling at a custom interval. |
onDataPointClick() | onDataPointClick(string $event): self | Dispatch a Livewire event on click. |
LiveCharts::bar() ->pollEvery(15) ->onDataPointClick('drilldown');Type constants
Section titled “Type constants”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.
Class-based equivalents
Section titled “Class-based equivalents”When extending Chart directly, every fluent setter has a corresponding overridable method:
| Fluent | Class-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.