Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Repository files navigation

Atelier Chart

Accessible SVG charts for PHP, with typed models, layout, and themes.

PHP Version PHPUnit PHPStan License

Compare categories, show change, or display proportions with fourteen chart families. Builders turn your values into immutable models; the renderer produces SVG with accessible titles and data descriptions.

use Atelier\Chart\Chart;

echo Chart::render(Chart::bar()
    ->series('Revenue', ['Q1' => 18, 'Q2' => 27, 'Q3' => 24, 'Q4' => 35])
    ->build());

Examples from the catalogue: grouped bars and line charts.

Quarterly revenue compared with grouped bars Multiple series displayed as line charts

Atelier Layout calculates the plot geometry and Atelier SVG supplies the output document. Rendering runs in PHP without JavaScript, a browser, or an external binary. Each SVG contains one chart; its viewBox lets it scale to the space available.

Catalogue · Themes · SVG output · Errors · Gallery · Documentation

Installation

composer require atelier/chart

Requires PHP 8.3+ and the atelier/layout and atelier/svg packages. Composer installs the package dependencies.

Quick start

<?php

declare(strict_types=1);

use Atelier\Chart\Chart;

require __DIR__.'/vendor/autoload.php';

$model = Chart::bar()
    ->title('Quarterly revenue')
    ->description('Revenue by quarter for 2025 and 2026, in millions.')
    ->series('2025', ['Q1' => 18, 'Q2' => 32, 'Q3' => 24, 'Q4' => 42])
    ->series('2026', ['Q1' => 26, 'Q2' => 24, 'Q3' => 38, 'Q4' => 35])
    ->build();

echo Chart::render($model);

build() validates the data and returns an immutable model. Chart::render() returns its SVG markup. The following snippets reuse this model, its imports, and the autoloader. See Getting started for saving the result and choosing a chart family.

Catalogue

Revenue by quarter for 2025 and 2026
Bar charts
Horizontal stacks compare roadmap allocation across Platform, Studio, and Docs
Stacked bar charts
Population magnitudes by age group with women to the right and men to the left
Diverging bar charts
Organic and referral signups from Monday to Sunday
Line charts
Visits over eight days
Area charts
Current product qualities compared with the target profile
Radar charts
Revenue share across four sales channels
Pie charts
Traffic share across acquisition sources
Donut charts
Customer age compared with annual spend
Scatter plots
Growth and margin by market, with revenue encoded as bubble area
Bubble charts
Current release confidence on a zero to one hundred scale
Gauges
Signups generally rising over seven days
Sparklines
Nine weeks of activity shown as a seven-row intensity matrix
Activity charts
Production, pause, and production segments occupying one half, one eighth, and three eighths of the strip
Strip charts

Themes

Pass a theme when rendering, without rebuilding the model:

use Atelier\Chart\Theme\Theme;

echo Chart::render($model, Theme::warm());

The presets are default, alto, dark, mono, and warm. A theme owns the palette, background, text, axes, and grid colours. Derive one with with() or supply a custom theme; see Themes.

SVG output

Chart::renderDocument($model) returns an Atelier SVG document for further composition. The default output includes accessibility information; CSS classes and data attributes are optional:

use Atelier\Chart\Renderer\Svg\SvgRenderOptions;

echo Chart::render($model, options: new SvgRenderOptions(
    classes: true,
    dataAttributes: true,
));

Enable these options when a stylesheet or script needs to address chart elements. They also apply to Chart::renderDocument() and SvgRenderer.

Error handling

Invalid or incompatible input throws Atelier\Chart\Exception\InvalidArgumentException. All package exceptions implement Atelier\Chart\Exception\ExceptionInterface. Required series counts, category order, and accepted value ranges depend on the chart family.

See Handle invalid input for a complete example and numeric precision when working with large integers or very small values.

Gallery

From a repository checkout with dependencies installed:

php examples/generate.php

Writes examples/output/index.html with examples of the chart families and themes.

Documentation

  • Getting started: build, render, and save a first chart.
  • Chart types: choose a family and explore illustrated variants.
  • Series: organize categories, points, and composition data.
  • Layout: control chart dimensions, axes, labels, and legends.
  • Scales: understand default domains and set consistent scales across charts.
  • Labels: format displayed values.
  • Themes: use a preset or define the visual roles.

Read the complete guides and generated illustrations in docs/.

Contributing

Contributions are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.

Before submitting code, run:

composer qa
composer coverage

Changes to public behaviour need tests and a documentation update. Keep line coverage at 95% or higher. Coverage reporting requires PCOV or Xdebug.

Support

Bug reports, security disclosures, and contribution guidelines are collected at ateliersvg.com/support.

License

Atelier Chart is released under the MIT License.

About

Accessible SVG charts for PHP, with typed models, layout, and themes.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages