Search by

consoletvs / charts

ErikCampobadal

Build charts in PHP and print them in Blade: Chart.js, ECharts, ApexCharts, Highcharts and more for Laravel, with Livewire and Inertia support.

Package info

github.com/ConsoleTVs/Charts

Homepage

Documentation

pkg:composer/consoletvs/charts

Fund package maintenance!

Patreon

Statistics

Installs: 4 491 044

Dependents: 31

Suggesters: 0

Stars: 86

Open Issues: 5

8.0.0 2026-11-29 01:48 UTC

This package is auto-updated.

Last update: 2026-11-29 10:57:28 UTC


README

Charts logo

Charts

Build charts in PHP, print them in Blade. A Laravel package for eight JavaScript charting libraries.

Latest version on Packagist Total downloads PHP version Tests License

Charts describes a chart (labels, datasets, options) in a PHP class and prints it in Blade. The package writes the HTML and the JavaScript for the charting library you picked, can load the data over AJAX with a loading animation, updates charts live from Livewire and hands them to Inertia as props. The JavaScript libraries are not bundled: your page loads the one you use.

Features

  • Eight libraries behind one fluent API: labels(), dataset(), options(), load().
  • A <x-charts::chart> Blade component, or two plain calls (container() and script()).
  • php artisan make:chart generates a chart class for the library of your choice.
  • Library specific helpers (title(), color(), ...) with the real option names of each library.
  • Data inline or fetched from an endpoint, with a spinner while it loads.
  • Livewire live updates and Inertia props (toArray()).
  • Safe to render twice: works with Turbo, Livewire navigation and View Transitions.
  • Natively typed (PHP 8.3), PHPStan level 9, tested against real browsers (Chromium, Firefox, WebKit).

Supported libraries

Library make:chart key Major License
Chart.js chartjs 4 MIT
ECharts echarts 6 Apache-2.0
Highcharts highcharts 13 Commercial (free for non-commercial use)
Frappe Charts frappe 2 MIT
FusionCharts fusioncharts 4 Commercial
Billboard.js billboard 4 MIT
ApexCharts apexcharts 8 Dual: free under USD 2M annual revenue, otherwise commercial
TradingView Lightweight Charts lightweightcharts 5 Apache-2.0, attribution to TradingView required

The package itself is MIT. The licenses above are the libraries' own: check that yours covers your use.

Requirements

  • PHP 8.3 or newer
  • Laravel 12 or 13

Installation

composer require consoletvs/charts:^8.0

The service provider is discovered automatically. Optionally publish the config (default_library, used by make:chart) and the views:

php artisan vendor:publish --tag=charts_config
php artisan vendor:publish --tag=charts_views

Quick start

Generate a chart class (the second argument is the library key, see the table above):

php artisan make:chart SalesChart chartjs   # creates app/Charts/SalesChart.php

Build it in a controller:

use App\Charts\SalesChart;

class DashboardController
{
    public function __invoke()
    {
        $chart = new SalesChart;
        $chart->labels(['Jan', 'Feb', 'Mar']);
        $chart->dataset('Users', 'line', [10, 20, 15])->color('#4f46e5');

        return view('dashboard', ['chart' => $chart]);
    }
}

Load the library and render the chart in Blade:

<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>

<x-charts::chart :chart="$chart" />

Prefer plain calls? {!! $chart->container() !!} and {!! $chart->script() !!} print the same thing.

Livewire and Inertia

  • Livewire: give the chart a stable id with $chart->id('sales') and push new data with $this->dispatch('charts:update', ...$chart->updatePayload()). See the Livewire guide.
  • Inertia: send $chart->toArray() as a prop and draw it with a small client helper. See the Inertia guide.

Documentation

The full documentation, with one page per library, is at charts.erik.cat: getting started, libraries and the changelog. Its source is in docs/. Every public method in src/ also has a docblock with an example. For AI agents there are /llms.txt and /llms-full.txt.

Upgrading

Coming from 6.x? Read UPGRADE.md (also on the docs site). Every release is listed in CHANGELOG.md.

Versions and support

Version Branch Status
8.x main Active: new features and fixes
6.x 6.x Security and bug fixes only

There is no version 7 on purpose; see Versions and support for why.

Contributing

Issues and pull requests are welcome. Read CONTRIBUTING.md first and follow the Code of Conduct.

Security

Please do not open a public issue for a vulnerability. Report it privately as described in SECURITY.md.

License

Charts is open source software released under the MIT license.