Search by

nervure / symfony

BenMacha

Symfony UX integration for nervure: animated SVG charts, maps and dashboards in Twig, with a Twig component, a Twig function and a Stimulus controller.

Package info

github.com/nervurejs/symfony

Homepage

Issues

Documentation

Type:symfony-bundle

pkg:composer/nervure/symfony

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

v0.14.0 2026-12-02 23:12 UTC

This package is not auto-updated.

Last update: 2026-12-03 05:41:04 UTC


README

Animated SVG charts, maps and dashboards of nervure in Twig: a Twig component, a Twig function and a Stimulus controller, for AssetMapper or Webpack Encore, with Turbo and Live Components.

Documentation: https://nervurejs.github.io/guide/symfony-laravel

Install

composer require nervure/symfony

Symfony Flex enables the bundle, adds the controller to assets/controllers.json and, with AssetMapper, adds nervure to importmap.php. Without Flex:

// config/bundles.php
BenMacha\UxNervure\NervureBundle::class => ['all' => true],
php bin/console importmap:require nervure                          # AssetMapper
npm install nervure --save-dev && npm install ./vendor/nervure/symfony/assets   # Webpack Encore

and in assets/controllers.json:

{
  "controllers": {
    "@nervure/symfony": { "chart": { "enabled": true, "fetch": "eager" } }
  }
}

PHP 8.2+, Symfony 6.4, 7 or 8.

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 length

Use

use BenMacha\UxNervure\Chart;

$spec = Chart::xy()
    ->categories(['Jan', 'Feb', 'Mar'])
    ->series('Orders', [120, 180, 150], kind: 'bar')
    ->format(currency: 'EUR');
<twig:Nervure:Chart :spec="spec" height="300" theme="dark" toolbar />

{{ render_nervure_chart(spec, {height: 300, animation: 'visible'}) }}

A spec is a PHP array or a Chart. The builder knows xy, pie, gauge, kpi, map and timeline; Chart::of('sankey', [...]) and ->with('field', $value) reach every other type and field. The specs of the 89 chart types: https://nervurejs.github.io/charts/

Other attributes of the component (class, id, data-*) go on the chart element.

Turbo and Live Components

The chart is removed with its element, and drawn again when its spec changes: a Turbo Stream that replaces the element, a Turbo Frame, or a Live Component that renders again.

#[AsLiveComponent]
final class Sales
{
    use DefaultActionTrait;

    #[LiveProp(writable: true)]
    public string $year = '2026';

    public function spec(): Chart
    {
        return Chart::xy()->categories([...])->series('Sales', [...]);
    }
}
<div {{ attributes }}>
    <select data-model="year">…</select>
    <twig:Nervure:Chart :spec="this.spec" />
</div>

Events

document.addEventListener('nervure--symfony--chart:connect', (event) => {
  const chart = event.detail.chart; // chart.toPNG(), chart.setColor(), chart.toggle()…
});

License

MIT, Ali Ben Macha.