ob/highcharts-bundle
Symfony bundle that simplifies using Highcharts by generating chart configuration in PHP and rendering via Twig extensions. Build rich, interactive graphs with less JS and DRY chart code. Note: Highcharts requires a commercial license for commercial use.
Pros:
Series, Options, Chart) aligns well with Laravel’s PHP-first paradigm, enabling reusable, testable chart logic.Series) can be extracted and repurposed with minimal changes, avoiding tight Symfony coupling.Cons:
ContainerAware or EventDispatcher must be replaced with Laravel equivalents (e.g., ServiceProvider, Event facade), risking subtle bugs.Core Viability:
spatie/laravel-highcharts).routes/api.php.Challenges:
{% highcharts_chart %}) must be replaced with Blade directives or PHP-based rendering (e.g., {{ $chart->render() }}).ContainerAware and EventDispatcher dependencies require refactoring to Laravel’s Container or manual implementations.series.dataLabels.formatter).High:
accessibility, sankey charts), requiring manual JS overrides.Medium:
mix aliases).Low:
Series/Options classes are framework-agnostic and easy to adapt.accessibility, stock charts) required? If so, is the team prepared to fork/patch the bundle?import())?// Blade directive (AppServiceProvider)
Blade::directive('highchart', function ($expression) {
return "<?php echo app('highcharts')->chart($expression)->toHtml(); ?>";
});
// Highcharts AJAX endpoint
Highcharts.ajax({
url: '/api/charts/data',
success: function(data) { /* update chart */ }
});
public/vendor/ or node_modules)?Compatibility Matrix:
| Layer | Symfony Bundle | Laravel Adaptation | Notes |
|---|---|---|---|
| PHP Classes | Series, Options, Chart |
Reusable as-is or in a new package | No changes needed. |
| Templating | Twig extensions ({% highchart %}) |
Blade directives or PHP rendering | Requires custom AppServiceProvider. |
| Dependency Injection | ContainerAware |
Laravel ServiceProvider or standalone |
Replace getContainer() with app(). |
| Event System | EventDispatcher |
Laravel Event facade or manual hooks |
Use event(new ChartBuilt($chart)). |
| Asset Management | Symfony Asset component |
Laravel Mix/Vite or manual public/ files |
Use mix.copy() for Highcharts assets. |
| Highcharts Version | v4.0 (2015) | Upgrade to v10+ (if needed) | May require JS config patches. |
Laravel-Specific Tools:
wire:model binding to chart data).Series::setData($model->toArray()).// resources/js/app.js
import Highcharts from 'highcharts';
window.Highcharts = Highcharts;
Phase 1: Core PHP Extraction (1–2 days)
laravel-highcharts).Series, Options, and Chart classes to src/Highcharts.ContainerAware with Laravel’s Container or remove DI entirely.// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('highcharts', function () {
return new \Highcharts\Chart();
});
}
Phase 2: Templating Layer (2–3 days)
AppServiceProvider:
Blade::directive('highchart', function ($expression) {
return "<?php echo app('highcharts')->chart($expression)->render(); ?>";
});
@highchart('lineChart', ['title' => 'Sales', 'data' => $salesData])
Chart service into controllers/views:
// Controller
public function dashboard(Chart $chart) {
$chart->setTitle('Sales')->setData($salesData
How can I help you explore Laravel packages today?