Symfony and Laravel
Two Composer packages bring nervure to PHP: nervure/symfony, a Symfony UX bundle, and nervure/laravel, for Blade and Livewire. Both take a spec as a PHP array or from a small builder, and draw it in the browser with nervure. The web component remains a way without a package.
Symfony: nervure/symfony
PHP 8.2+, Symfony 6.4, 7 or 8, AssetMapper or Webpack Encore.
composer require nervure/symfonySymfony Flex enables the bundle, adds its Stimulus controller to assets/controllers.json and, with AssetMapper, adds nervure to importmap.php. Without Flex: add BenMacha\UxNervure\NervureBundle::class => ['all' => true] to config/bundles.php, run php bin/console importmap:require nervure, and enable "@nervure/symfony": { "chart": { "enabled": true, "fetch": "eager" } } in assets/controllers.json. With Webpack Encore, npm install nervure as well.
Configure
# config/packages/nervure.yaml
nervure:
theme: auto # light, dark or auto
locale: ~ # the language of the page by default
animation: true # true, false, or visible: plays when the chart comes into view
toolbar: false # export button (SVG, PNG, CSV)
zoom: false
height: 300 # pixels, or any CSS lengthThe Twig component
use BenMacha\UxNervure\Chart;
#[Route('/orders')]
public function orders(OrderRepository $orders): Response
{
$rows = $orders->countByMonth();
return $this->render('orders.html.twig', [
'spec' => Chart::xy()
->categories(array_column($rows, 'month'))
->series('Orders', array_column($rows, 'total'), kind: 'bar')
->format(currency: 'EUR'),
]);
}<twig:Nervure:Chart :spec="spec" height="300" theme="dark" toolbar />Each attribute overrides the configuration: height, theme, locale, animation, toolbar, zoom. The others (class, id, data-*) go on the chart element.
The Twig function
{{ render_nervure_chart(spec, {height: 300, animation: 'visible', attr: {class: 'card'}}) }}Specs
A spec is a PHP array, exactly as in JavaScript, or a Chart:
Chart::xy()->categories(['Jan', 'Feb'])->series('Orders', [12, 18], kind: 'bar')->format(currency: 'EUR');
Chart::pie()->slice('Shop', 42)->slice('Web', 35)->with('inner', 0.6);
Chart::gauge(72, 100)->with('unit', '%');
Chart::kpi('Revenue', 248000)->with('previous', 212000)->format(currency: 'EUR', compact: true);
Chart::map(file_get_contents('countries.json'))->values(['FR' => 12, 'TN' => 7]);
Chart::timeline()->bar('Build', new DateTime('2026-01-05'), new DateTime('2026-01-20'));
Chart::of('sankey', ['nodes' => [...], 'links' => [...]]);->with('field', $value) sets any field. Every chart type and its fields: Charts.
Turbo
A Turbo Frame or a Turbo Stream that replaces the element replaces the chart; the controller removes the old one. A Turbo Stream that only changes the spec draws the new data on the same chart. A Turbo 8 page refresh with morphing draws the chart again.
Live Components
#[AsLiveComponent]
final class Sales
{
use DefaultActionTrait;
#[LiveProp(writable: true)]
public string $year = '2026';
public function __construct(private readonly SalesRepository $sales) {}
public function spec(): Chart
{
$rows = $this->sales->byMonth($this->year);
return Chart::xy()->categories(array_keys($rows))->series('Sales', array_values($rows));
}
}<div {{ attributes }}>
<select data-model="year">
<option>2025</option>
<option>2026</option>
</select>
<twig:Nervure:Chart :spec="this.spec" />
</div>The drawing sits in a data-live-ignore element; on each re-render, Live Components update the spec of its parent and the chart draws the new data.
Events
document.addEventListener('nervure--symfony--chart:connect', (event) => {
const chart = event.detail.chart; // chart.toPNG(), chart.setColor(), chart.toggle()…
});nervure--symfony--chart:update follows each new spec.
Mercure
For a chart that moves with your data:
import { append, events, live } from 'nervure/live';
document.addEventListener('nervure--symfony--chart:connect', ({ detail: { chart } }) => {
live(chart, spec, events('https://example.com/.well-known/mercure?topic=prices'), {
apply: (data, previous) => append(previous, data.time, { Price: data.price }, 60),
});
});Laravel: nervure/laravel
PHP 8.2+, Laravel 11 or 12.
composer require nervure/laravel
php artisan vendor:publish --tag=nervure-config # optionalConfigure
// config/nervure.php
return [
'theme' => env('NERVURE_THEME', 'auto'), // light, dark or auto
'locale' => null,
'animation' => true, // true, false or 'visible'
'toolbar' => false,
'zoom' => false,
'height' => 300,
'assets' => env('NERVURE_ASSETS', 'cdn'), // cdn or vite
'version' => '0.14.0', // nervure version loaded from the CDN
'cdn' => 'https://cdn.jsdelivr.net/npm/nervure@{version}/cdn/nervure.min.js',
];Load nervure
From the CDN, at the version pinned in the configuration, once in the layout:
@nervureScriptsWith Vite, set NERVURE_ASSETS=vite, npm install nervure, and:
// resources/js/app.js
import 'nervure/element';
import '../../vendor/nervure/laravel/resources/js/nervure-blade.js';@nervureScripts('nonce') adds a CSP nonce; with Vite::useCspNonce() it is added by itself.
The Blade component
use BenMacha\LaravelNervure\Facades\Nervure;
$spec = Nervure::xy()
->categories(['Jan', 'Feb', 'Mar'])
->series('Orders', [120, 180, 150], kind: 'bar')
->format(currency: 'EUR');<x-nervure-chart :spec="$spec" height="300" theme="dark" toolbar />The facade has the same builder as the Symfony bundle: Nervure::xy(), pie(), gauge(), kpi(), map(), timeline(), of(). A PHP array works too. Outside Blade, Nervure::render($spec, ['height' => 300]) returns the HTML.
Livewire
Nothing to add: the drawing sits in a wire:ignore element, and the spec on its wrapper. When the component renders again, Livewire updates the spec and the chart draws the new data.
final class Sales extends Component
{
public string $year = '2026';
public function render()
{
$rows = Sale::byMonth($this->year);
return view('livewire.sales', [
'spec' => Nervure::xy()->categories(array_keys($rows))->series('Sales', array_values($rows)),
]);
}
}<div>
<select wire:model.live="year">
<option>2025</option>
<option>2026</option>
</select>
<x-nervure-chart :spec="$spec" wire:key="sales-chart" />
</div>Inertia
Use the React, Vue or Svelte component.
Without a package: the web component
The <nervure-chart> web component needs no build tool and follows Turbo and Livewire: it cleans up when its element goes away.
Symfony
php bin/console importmap:require nervure/element// assets/app.js
import 'nervure/element';<nervure-chart style="height: 320px" toolbar spec="{{ spec|json_encode|e('html_attr') }}"></nervure-chart>Your own Stimulus controller, with Webpack Encore or AssetMapper:
// assets/controllers/chart_controller.js
import { Controller } from '@hotwired/stimulus';
import { chartController } from 'nervure/stimulus';
export default chartController(Controller);<div {{ stimulus_controller('chart', { spec: spec, options: { toolbar: true } }) }} style="height: 320px"></div>It draws again when its value changes, and dispatches chart:ready with the chart.
Laravel
// resources/js/app.js
import 'nervure/element';<nervure-chart style="height: 320px" toolbar spec="{{ json_encode($spec) }}"></nervure-chart>With Livewire, keep the element out of the re-render and send it the new spec:
<div wire:ignore>
<nervure-chart id="orders" style="height: 320px" spec="{{ json_encode($spec) }}"></nervure-chart>
</div>$this->dispatch('orders-changed', spec: $this->spec());Livewire.on('orders-changed', ({ spec }) => {
document.querySelector('#orders').spec = spec;
});Rails, Django, WordPress
The same web component, with one script tag.