Skip to content

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.

bash
composer require nervure/symfony

Symfony 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 ​

yaml
# 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 length

The Twig component ​

php
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
<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 ​

twig
{{ 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:

php
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 ​

php
#[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));
    }
}
twig
<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 ​

js
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:

js
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.

bash
composer require nervure/laravel
php artisan vendor:publish --tag=nervure-config   # optional

Configure ​

php
// 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:

blade
@nervureScripts

With Vite, set NERVURE_ASSETS=vite, npm install nervure, and:

js
// 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 ​

php
use BenMacha\LaravelNervure\Facades\Nervure;

$spec = Nervure::xy()
    ->categories(['Jan', 'Feb', 'Mar'])
    ->series('Orders', [120, 180, 150], kind: 'bar')
    ->format(currency: 'EUR');
blade
<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.

php
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)),
        ]);
    }
}
blade
<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 ​

bash
php bin/console importmap:require nervure/element
js
// assets/app.js
import 'nervure/element';
twig
<nervure-chart style="height: 320px" toolbar spec="{{ spec|json_encode|e('html_attr') }}"></nervure-chart>

Your own Stimulus controller, with Webpack Encore or AssetMapper:

js
// assets/controllers/chart_controller.js
import { Controller } from '@hotwired/stimulus';
import { chartController } from 'nervure/stimulus';

export default chartController(Controller);
twig
<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 ​

js
// resources/js/app.js
import 'nervure/element';
blade
<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:

blade
<div wire:ignore>
    <nervure-chart id="orders" style="height: 320px" spec="{{ json_encode($spec) }}"></nervure-chart>
</div>
php
$this->dispatch('orders-changed', spec: $this->spec());
js
Livewire.on('orders-changed', ({ spec }) => {
  document.querySelector('#orders').spec = spec;
});

Rails, Django, WordPress ​

The same web component, with one script tag.