matheusmarnt / livecharts
Elevate your data visualization with reactive charts in Laravel.
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0||^12.0||^13.0
- livewire/livewire: ^3.0||^4.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1
- orchestra/testbench: ^8.0||^9.0||^10.0
- pestphp/pest: ^3.0||^4.0
- pestphp/pest-plugin-arch: ^3.0||^4.0
- pestphp/pest-plugin-laravel: ^3.0||^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
- dev-main
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.0
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v1.19.0
- v1.18.1
- v1.18.0
- v1.17.0
- v1.16.1
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-docs/v2.7.4-locale-rename
- dev-release-please--branches--main
- dev-fix/lang-dir-locale-mismatch
- dev-fix/translation-direct-namespace
- dev-docs/v2.7.2-install-assets-translations
- dev-fix/install-vendor-assets-translations
- dev-docs/update-instructions-doc
- dev-fix/phpstan-colors-list-type
- dev-test/coverage-thememode-colorvalue
- dev-docs/v2.7.0-updates
- dev-fix/colorvalue-reconstruction-sidecar-paths
- dev-feat/theme-aware-color-tokens
- dev-docs/v2-5-x-comprehensive
- dev-fix/scripts-head-render-order
- dev-fix/apexcharts-adapter-empty-arrays
- dev-feat/engine-available-types
- dev-fix/alpine-constructor-collision
- dev-fix/scripts-blade-dir-resolution
- dev-ci/deploy-docs-node22
- dev-docs/livecharts-site
- dev-docs/sync-readme-installation-v2.4
- dev-ci/run-tests-paths-include-js
- dev-feat/preview-open-browser
- dev-test/phase-4-arch-and-use-cases
- dev-feat/bundle-chartjs-plugins
- dev-feat/bundle-engine-assets
- dev-feat/js-build-pipeline
- dev-refactor/base-engine-adapter
- dev-refactor/chart-make-options
- dev-refactor/livewire-uuid
- dev-docs/scoutify-pattern
- dev-refactor/engine-factory-singleton
- dev-feat/install-publish-stubs
- dev-fix/alpine-lifecycle
- dev-feat/chart-polling
- dev-feat/register-engine-static
- dev-ci/matrix-expand
- dev-chore/phpstan-level-8
- dev-fix/livewire-blade-attributes
- dev-feat/lang-files
- dev-feat/missing-exceptions
- dev-feat/docs-site
- dev-feat/config-helpers
- dev-feat/mixed-charts
- dev-feat/preview-command
- dev-feat/branding-readme
- dev-feat/asset-resilience
- dev-feat/chartjs-plugins
- dev-feat/websocket-integration
- dev-feat/full-integration
- dev-feat/interaction-events
- dev-feat/engine-versions-update
- dev-feat/engine-v2026-expansion
- dev-feat/asset-injection
- dev-feat/chartjs-expansion
- dev-feat/skeleton-setup
This package is auto-updated.
Last update: 2026-05-04 03:49:38 UTC
README
LiveCharts
Reactive chart abstraction for Laravel — pure PHP API, multi-engine rendering, Livewire delivery.
LiveCharts unifies ApexCharts and Chart.js behind a single fluent PHP API. Define charts in PHP, render them with one Livewire component, and update them reactively from your application state — no JavaScript boilerplate, no engine-specific configuration leaking into your views.
Features
- Fluent + class-based builders —
LiveCharts::line()->labels(...)->dataset(...)orclass extends Chart - 18 chart types — line, bar, area, pie, donut, radar, scatter, bubble, heatmap, range bar, radial bar, polar area, box plot, treemap, candlestick, matrix, sankey, plus a generic factory
- Multi-engine — ApexCharts and Chart.js out of the box, with
LiveCharts::registerEngine()for custom adapters - Livewire-native rendering — single
<livewire:livecharts :chart="$chart" />component handles mount, hydration, and re-render - Reactive updates — bind chart data to Livewire properties; the component re-renders when state changes
- Polling —
Chart::poll(5000)+wire:poll="refresh"integration with alivecharts:refreshedevent for userland data hydration - Interaction events —
onDataPointClick,onZoom,onSelection,onScrollmap directly to Livewire events - Broadcasting — push chart updates over Laravel Echo channels with
broadcastOn()/broadcastAs() - Theme-aware color tokens — 289-case
TwColorenum (all Tailwind v4 families + 4 extensions × 11 shades) withdark:/light:named-arg API:->titleColor(dark: TwColor::Amber300, light: TwColor::Amber600). Charts re-color live on dark-mode toggle — no Livewire roundtrip - Palette presets —
->palette(TwPalette::Vibrant)auto-fills dataset colors from theme-aware preset schemes - Typography —
->titleFont(size: 18, weight: 'bold', family: 'Inter')for title, legend, and tooltip - Theme detection —
auto,light, ordarkmodes; JS observer watches<html class="dark">(orprefers-color-scheme) and re-colors charts live - Local-first assets with CDN fallback — engine bundles (
apexcharts.js,chartjs.js) and Chart.js plugin bundles (treemap/matrix/sankey/financial/luxon/adapter-luxon) ship pre-built inresources/dist; switch betweenlocal,cdn, orbothvia config - Vite build pipeline — lib-mode IIFE outputs for
livecharts.js+ every engine and plugin shim, verified in CI - Stub publishing —
livecharts:installcan publish chart class stubs tostubs/livechartsfor project-level customization - Browser preview —
php artisan livecharts:previewlaunches a gallery of every chart type in your default browser - i18n — ships with
en,pt_BR, andestranslations - Type-safe — PHPStan level 8, PHP 8.2+, strict types throughout
Quick Start
composer require matheusmarnt/livecharts php artisan livecharts:install
This will:
- Publish
config/livecharts.php - Copy the LiveCharts JS runtime + engine bundles to
public/vendor/livecharts/js(local-first delivery with CDN fallback by default —LIVECHARTS_ASSETS_MODE=both) - Optionally publish chart class stubs to
stubs/livecharts
Note: The default asset mode is
both(local first, CDN fallback). The files inpublic/vendor/livecharts/js/must exist for this to work. If you skip the install step or need to restore the assets after deployment, run:php artisan vendor:publish --tag=livecharts-assets --forceIf you prefer no local files at all, set
LIVECHARTS_ASSETS_MODE=cdnin.env— no publish step needed.
Then build a chart and render it:
use Matheusmarnt\LiveCharts\Facades\LiveCharts; $chart = LiveCharts::line() ->title('Monthly Revenue') ->labels(['Jan', 'Feb', 'Mar']) ->dataset('2026', [100, 200, 150]) ->colors(['#3B82F6']);
<livewire:livecharts :chart="$chart" />
Place the asset directive once in your layout, before @livewireScripts and before the closing </body> tag (or in the <head> when using a Blade layout with @extends/@section):
{{-- must come BEFORE @livewireScripts — livecharts.js registers Alpine components before Alpine starts --}} @liveChartsScripts @livewireScripts
Building Charts
Fluent builder
Every method returns $this, so chains read top-down:
LiveCharts::bar() ->title('Sales by Region') ->subtitle('Q1 2026') ->labels(['North', 'South', 'East', 'West']) ->dataset('Sales', [400, 300, 600, 250]) ->colors(['#10B981']) ->stacked() ->height(420) ->theme('auto');
Available factories: line, bar, area, pie, donut, radar, scatter, bubble, heatmap, rangeBar, radialBar, polarArea, boxPlot, treemap, candlestick, matrix, sankey, plus make() for the generic factory.
Class-based charts
Generate a dedicated class for reusable charts:
php artisan make:chart RevenueChart --type=bar
namespace App\Charts; use Matheusmarnt\LiveCharts\Charts\Chart; use Matheusmarnt\LiveCharts\Charts\Dataset; class RevenueChart extends Chart { protected string $type = 'bar'; public function __construct() { parent::__construct(); $this ->title('Revenue') ->labels(['Jan', 'Feb', 'Mar']) ->datasets([ Dataset::make('2026')->data([400, 300, 600])->color('#10B981'), ]); } }
<livewire:livecharts :chart="new App\Charts\RevenueChart" />
Stubs: running
livecharts:installand accepting the stubs prompt publishes the generator stub tostubs/livecharts/chart.stub. Edit that file to customize the boilerplate emitted bymake:chart.
Reactive Charts
Polling
$chart->poll(5000); // refresh every 5 seconds
The Livewire component subscribes via wire:poll="refresh" and dispatches a browser event on every tick:
window.addEventListener('livecharts:refreshed', (e) => { // e.detail.id — chart DOM id })
Hydrate fresh data inside refresh() on a parent Livewire component, or react to the event on the client.
Click and zoom events
$chart ->onDataPointClick('chart-clicked') ->onZoom('chart-zoomed') ->onSelection('chart-selected');
In the parent component:
use Livewire\Attributes\On; #[On('chart-clicked')] public function handle(array $data): void { // $data: ['seriesIndex' => 0, 'dataPointIndex' => 2, 'value' => 150, 'label' => 'Mar'] }
Broadcasting
$chart->broadcastOn('private-charts.'.$user->id)->broadcastAs('chart.updated');
Subscribe via Laravel Echo and the chart re-renders when the channel fires.
Multi-Engine
The default engine is apexcharts. Override globally in config/livecharts.php or per chart:
LiveCharts::line()->engine('chartjs')->labels(...)->dataset(...);
Register a custom adapter at runtime:
use App\LiveCharts\Engines\HighchartsAdapter; use Matheusmarnt\LiveCharts\Facades\LiveCharts; LiveCharts::registerEngine('highcharts', HighchartsAdapter::class);
Implement Matheusmarnt\LiveCharts\Contracts\EngineAdapter and the engine becomes selectable from any chart.
Commands
| Command | Description |
|---|---|
livecharts:install |
Publish config, copy the JS runtime + engine bundles, optionally publish chart stubs |
make:chart {name} {--type=} {--engine=} |
Generate a new chart class under app/Charts; --type/--engine derived from Chart::TYPES and EngineFactory::names() |
livecharts:preview {--no-open} |
Open the gallery of every chart type at /livecharts/preview in your default browser; --no-open only prints the URL |
Documentation
- Installation guide — step-by-step setup, asset modes, engine selection, customization
Testing
composer test
Runs the Pest suite (288 tests) against the package's testbench harness — including 17 Pest arch rules, payload + adapter routing for every chart type, Livewire color-roundtrip tests (Bugs 1 & 5), ApexCharts themed-color path tests, script-stack idempotency tests, and integration tests for UC-01 dashboard, UC-02 drill-down, UC-03 polling, and UC-04 multi-tenant flows. CI matrix: PHP 8.2-8.5 × Laravel 11/12/13 × Livewire 3/4 × prefer-lowest/stable × Ubuntu/Windows, with a --min=90 coverage gate and PHPStan level 8 enforcement.
Changelog
See CHANGELOG for release history.
Contributing
See CONTRIBUTING for details.
Security
If you discover a security vulnerability, please email matheusmarnt@gmail.com instead of opening a public issue.
Credits
License
MIT — see LICENSE.
