kalamurda/amcharts-bundle
Symfony bundle for integrating amCharts JavaScript charts into your application. It provides configuration and rendering helpers to add interactive charts with less boilerplate, making it easier to wire amCharts assets and chart definitions into Symfony projects.
This is a Symfony bundle, not a Laravel package — there is no AmChartsServiceProvider, no auto-discovery, and no Blade directives. Treat it as a reference implementation first and a dependency second.
src/KalamurdaAmChartsBundle.php (or similar *Bundle class) — shows the DI extension entry point.src/DependencyInjection/ — the service definitions and config tree you'd need to replicate in a Laravel provider.src/Resources/views/ — the Twig templates that actually emit chart markup/JS.src/Resources/config/services.* — which services are public and what they depend on.symfony/http-kernel, symfony/dependency-injection, symfony/twig-bridge). Check the composer.json constraints against your PHP version — anything published in 2021 typically targets PHP 7.x/8.0 and Symfony 4/5.Realistic first step in Laravel:
// app/Support/AmCharts.php — a thin wrapper, not the bundle's container wiring
$chart = [
'type' => 'xy',
'data' => $rows,
'series' => [/* ... */],
];
return view('charts.bar', ['config' => $chart]);
{{-- resources/views/charts/bar.blade.php --}}
<div id="chart" style="width:100%;height:400px"></div>
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script>
am5.ready(function () {
const root = am5.Root.new("chart");
// hydrate from @json($config)
});
</script>
If the repo's builder classes are cleanly decoupled, you can new them directly from a Laravel service — that's the only sensible "leverage" path.
Pattern 1 — Config builder, not renderer. Use the bundle's PHP chart objects as DTOs to shape config server-side, then hand JSON to the client. This matches the package's likely design (Symfony bundles of this era typically build chart arrays in PHP and render via Twig). Map it to a Laravel ChartData value object:
class ChartData implements JsonSerializable
{
public function __construct(
public array $data,
public array $series = [],
public array $axes = [],
) {}
public function jsonSerialize(): array
{
return ['data' => $this->data, 'series' => $this->series, 'axes' => $this->axes];
}
}
Bind it in a service provider:
$this->app->singleton(ChartFactory::class, fn ($app) => new ChartFactory(
config('charts.default_theme', 'light')
));
Pattern 2 — API endpoint + JS fetch. The most portable workflow: a controller returns chart config, the browser renders it. Avoids Blade/Twig coupling entirely and works with Inertia, Livewire, or Alpine.
Route::get('/charts/revenue', fn () => response()->json(
ChartFactory::revenue()->jsonSerialize()
));
Pattern 3 — Blade component wrapper. If you port the Twig template, turn it into <x-amchart :config="$config" />. Keep the JS init in a single resources/js/amcharts.js module so Vite can bundle the amCharts npm package instead of a CDN script.
Pattern 4 — Livewire dynamic charts. Emit dispatch('chart-updated', config: @js($config)), listen in JS, and call chart.data.setAll(newData) or series.data.setAll(...). Don't re-init the chart root on every update — amCharts leaks instances otherwise.
Integration tips
npm i @amcharts/amcharts5) rather than the bundle's Resources/public assets, which won't be exposed by Laravel.ChartPresenter so controllers stay thin.twigbridge only as a last resort; porting a 30-line template is cheaper than a cross-framework shim.am5.Root, am5xy.XYChart) substantially.Class 'Symfony\Component\HttpKernel\Bundle\Bundle' not found unless Symfony components are installed, and even then the bundle won't auto-register in Laravel. You must manually translate Extension::load() into a ServiceProvider.symfony/* ^6/^7 support, and amCharts 5 incompatibility. Budget time for a fork.{{ amchart(...) }}) are unavailable. Anything that returns Twig\Markup or relies on Twig\Environment will fail — refactor to plain arrays/strings.assets:install has no Laravel equivalent; Resources/public is invisible to public/. Copy manually or, better, use npm.Configuration tree uses ->children()->... semantics; Laravel's config() merging is flat and will not validate types. If you port the tree, validate with a config/charts.php + a small schema check, or you'll get silent empty-series charts.Log::debug the failing service id; check for public: false services the bundle expects to inject.dd(json_encode($config)), paste into an amCharts codepen, and diff against the version's docs. Log the payload size — large datasets silently stall rendering.ChartRendererInterface in your app so you can swap the bundle out later.ChartFactory + Blade component. The package's value here is as a spec for chart config shape, not as a runtime dependency.How can I help you explore Laravel packages today?