PHPackages                             iliaal/fastchart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. iliaal/fastchart

ActivePhp-ext[Image &amp; Media](/categories/media)

iliaal/fastchart
================

Native C PHP extension for fast chart rendering: 26 chart families (line, bar, pie, scatter, bubble, stock with technical indicators, radar, polar, surface, contour, treemap, funnel, waterfall, heatmap, gauge, linear meter, gantt, box plot, area, bullet, pareto, calendar heatmap, sunburst, sankey, marimekko, vector) plus a 2-class Symbol family (Code128, QrCode). SVG-canonical pipeline rasterized via vendored plutovg + plutosvg; PNG / JPEG / WebP encoders via libpng / libjpeg-turbo / libwebp.

1.1.1(2w ago)29193(BSD-3-Clause AND MIT)CPHP &gt;=8.3CI passing

Since May 6Pushed 4d ago2 watchersCompare

[ Source](https://github.com/iliaal/fastchart)[ Packagist](https://packagist.org/packages/iliaal/fastchart)[ Docs](https://github.com/iliaal/fastchart)[ RSS](/packages/iliaal-fastchart/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)DependenciesVersions (10)Used By (0)

fastchart
=========

[](#fastchart)

[![Tests](https://github.com/iliaal/fastchart/actions/workflows/tests.yml/badge.svg)](https://github.com/iliaal/fastchart/actions/workflows/tests.yml)[![Version](https://camo.githubusercontent.com/fd14d863cc48a87dcfe9f2f6742a366ba93a29790458a0465c17dbaa63b589cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f696c6961616c2f6661737463686172743f6c6162656c3d76657273696f6e26736f72743d73656d766572)](https://github.com/iliaal/fastchart/releases)[![License: BSD-3-Clause](https://camo.githubusercontent.com/5b18cec5d64abf4a1fb017b12bcf376f4f1aa4c91aa28a9669664f8b2666eb62/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442d2d332d2d436c617573652d677265656e2e737667)](https://opensource.org/licenses/BSD-3-Clause)[![Follow @iliaa](https://camo.githubusercontent.com/a54521c97521f05fbadec4bd9bcba96ff1eeaffe756a6d7338b47a628cdeb39b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f466f6c6c6f772d40696c6961612d3030303030303f7374796c653d666c6174266c6f676f3d78266c6f676f436f6c6f723d7768697465)](https://x.com/intent/follow?screen_name=iliaa)

Native C PHP extension. 26 chart types behind a modern OO API with fluent setters and `final` classes. Line, area, bar, scatter, bubble, pie, radar, polar, surface, contour, gauge, gantt, box-plot, treemap, funnel, waterfall, heatmap, linear meter, plus a deep `StockChart`(seven candle styles, SMA / EMA / WMA overlays, volume + indicator panes).

SVG is the canonical render format. PNG / JPG / WebP outputs flatten text to glyph paths, run plutovg over the resulting SVG, and encode the RGBA buffer with libpng / libjpeg-turbo / libwebp. The same chart object serves a sharp `` for dashboards or a PNG for emails without rebuilding state. `renderToFile()` picks the encoder from the extension; `renderPng()` / `renderJpeg()` / `renderWebp()` / `renderSvg()` return bytes in-process.

[![fastchart: 26 chart types in one PHP extension](images/fastchart-hero.jpg)](images/fastchart-hero.jpg)

**[Live gallery →](https://iliaal.github.io/fastchart/v1-gallery.html)**. Side-by-side SVG / PNG / JPG / WebP renders for every chart family, with the source PHP shown above each row.

Status
------

[](#status)

v1.1: confidence-band area charts, cone-style funnels, smooth polar curves with overlay vectors, log-scale bubble plots, HTML image-map hot-spots on Bar / Pie / Scatter (`setImageMap` + `getImageMap`). v1.0 dropped libgd as a runtime dependency, rebuilt rasterization around vendored plutovg, and replaced `draw($canvas)` with `renderSvg/Png/Jpeg/Webp` + `renderToFile`. 26 chart types, 2-class Symbol family, 138 phpt tests. See [`CHANGELOG.md`](CHANGELOG.md)for the full breaking-change list.

Install
-------

[](#install)

### Via PIE (recommended)

[](#via-pie-recommended)

[PIE](https://github.com/php/pie) handles the configure / make / install cycle for you against your active PHP install:

```
pie install iliaal/fastchart
```

PIE picks up the latest tagged release from Packagist and respects your platform's `pkg-config` for the FreeType / libpng / libjpeg-turbo / libwebp probes. After install, enable the extension via your distribution's mechanism (e.g. `docker-php-ext-enable fastchart` on the official PHP images, or add `extension=fastchart` to `php.ini`).

### From source

[](#from-source)

Build manually against the PHP install you want to extend:

```
phpize
./configure --enable-fastchart
make -j
make test
```

Strict-warnings dev build (recommended for contributors):

```
./configure --enable-fastchart --enable-fastchart-dev
```

Runtime check:

```
php -d extension=./modules/fastchart.so \
  -r 'echo FastChart\Chart::version(), PHP_EOL;'
```

Requirements
------------

[](#requirements)

- PHP 8.1 or later (NTS or ZTS).
- **FreeType** development headers (`libfreetype-dev` / `freetype-devel`). Required, since text rendering depends on FreeType.
- **libpng / libjpeg-turbo / libwebp** development headers. Each is optional; config.m4 probes them independently via pkg-config and the corresponding `renderPng()` / `renderJpeg()` / `renderWebp()`is wired up only for libs that resolve at build time. A missing lib turns the matching method into a "format not compiled in" Error at call time; SVG output stays available regardless. `phpinfo()` reports the resolved version of each lib (or `(not compiled in)`) so you can audit a build.
- plutovg + plutosvg are vendored under `vendor/`; no separate install required.

Quick start
-----------

[](#quick-start)

The shortest path is the `renderToFile()` helper, which picks the encoder from the file extension:

```
(new FastChart\LineChart(640, 320))
    ->setTitle('Daily active users')
    ->setSeries([['data' => [820, 940, 870, 1020, 1180, 1250, 1340]]])
    ->setCategoryLabels(['Mon','Tue','Wed','Thu','Fri','Sat','Sun'])
    ->renderToFile('/tmp/dau.png');
```

`renderPng()`, `renderJpeg()`, and `renderWebp()` return the encoded bytes if you need them in memory. Raster compression knobs:

```
$chart->setJpegQuality(75);              // sticks on the chart instance;
$chart->renderJpeg();                    // ...used by every render call
$chart->renderJpeg(95);                  // per-call override (1..100)

$chart->renderWebp();                    // default quality 90
$chart->renderWebp(60);                  // smaller, lossier (1..100)

$chart->renderToFile('/tmp/out.webp');   // setJpegQuality only affects
                                         // .jpg; renderToFile uses the
                                         // built-in WebP default
```

PNG is always lossless; there's no quality knob. The encoder is libpng with default filter selection.

WebP has four encoder modes selectable via `setWebpMode()`. The default `WEBP_DRAWING` is tuned for chart-shaped content (flat fills, sharp edges); see the table in [`docs/examples/50_webp_modes.php`](docs/examples/50_webp_modes.php)for the speed/size trade-offs each mode picks.

```
$chart->setWebpMode(FastChart\Chart::WEBP_LOSSLESS);  // archival
$chart->setWebpMode(FastChart\Chart::WEBP_FAST);      // preview pipelines
$chart->setWebpMode(FastChart\Chart::WEBP_PHOTO);     // photo backgrounds
$chart->setWebpMode(FastChart\Chart::WEBP_DRAWING);   // back to default
```

Call `renderSvg()` on the same chart object for vector output: dashboards, print, anywhere infinite-zoom matters.

```
$chart = (new FastChart\LineChart(640, 320))
    ->setTitle('Daily active users')
    ->setSeries([['data' => [820, 940, 870, 1020, 1180, 1250, 1340]]])
    ->setCategoryLabels(['Mon','Tue','Wed','Thu','Fri','Sat','Sun']);

$svg = $chart->renderSvg();              // full ...
$chart->renderToFile('/tmp/dau.svg');    // same, written to disk

// Stitch several charts into one outer SVG document:
$fragment = $chart->drawSvgFragment();   // ...
```

Construction is identical for every output format; only the final render call differs. By default, SVG text is flattened to glyph outline paths (`SVG_TEXT_PATHS` mode). The resulting SVG is self- contained and renders identically in any viewer or rasterizer. For smaller files with selectable text, switch to native ``mode:

```
$chart->setSvgTextMode(FastChart\Chart::SVG_TEXT_NATIVE);
$svg = $chart->renderSvg();  // ~30% smaller; needs consumer text support
```

Raster outputs (PNG/JPG/WebP) always use the PATHS mode internally; plutovg has no text support of its own, so glyph flattening is what makes labels appear in the rasterized output.

Three static methods on `FastChart\Chart` rasterize caller-supplied SVG bytes through the same plutovg + libpng / libjpeg-turbo / libwebp pipeline. Useful for round-tripping `renderSvg()` output, or for stitching multiple `drawSvgFragment()` calls into one outer SVG and rasterizing the result, all in-process:

```
$png  = FastChart\Chart::svgToPng($svg);
$jpg  = FastChart\Chart::svgToJpeg($svg, 88, 0xFFFFFF);  // bg + quality
$webp = FastChart\Chart::svgToWebp($svg, 90, FastChart\Chart::WEBP_LOSSLESS);
```

Output dimensions come from the SVG's `width` / `height` / `viewBox`. SVG `` elements render blank because plutovg has no text engine, so text must be path-flattened first (fastchart's own SVG builder does this automatically). See [`docs/examples/51_svg_to_raster.php`](docs/examples/51_svg_to_raster.php)for a runnable demo and [`docs/specs/svg-to-raster.md`](docs/specs/svg-to-raster.md) for the full contract.

📊 Performance
-------------

[](#-performance)

Median in-memory render time at 1920×1080 on a single core (Intel i9-13950HX, PHP 8.4 release build NTS -O2, default font + DPI). SVG is the canonical output; PNG / WebP / JPG go through the same SVG build, then plutosvg + plutovg rasterize, then the format encoder (libpng / libwebp / libjpeg-turbo). The raster columns therefore add the rasterize cost on top of the SVG-only number.

ChartSVG msPNG msWebP msJPG msAreaChart0.1245.1934.0411.45BarChart0.2243.5435.1812.35BoxPlot0.0940.2630.749.95BubbleChart0.0652.8444.1814.84ContourChart0.1148.4641.1412.97Funnel0.0840.1531.599.53GanttChart0.1240.0830.9810.22GaugeChart0.0244.7533.7810.19Heatmap0.0543.2835.6211.85LineChart0.1145.4537.2311.81LinearMeter0.0238.6429.108.98PieChart0.0644.4233.8411.75PolarChart0.0247.6037.1011.48RadarChart0.0647.8936.4813.39ScatterChart0.1143.0532.4810.38StockChart0.2046.0040.8614.19SurfaceChart0.0640.0934.5010.35Treemap0.1139.7631.749.74Waterfall0.0939.2132.0510.08SVG stays well under a quarter-millisecond across the board (0.02 to 0.22 ms) because there's no rasterization; the backend appends strings into a `smart_str` via an allocation-free integer/fraction number emitter. The raster encoders split into three bands: JPG fastest (9-15 ms, libjpeg-turbo with 4:2:0 subsampling + SSSE3/NEON RGBA-pack), WebP middle (29-44 ms, libwebp with `WEBP_PRESET_DRAWING` + method=2 + multi-thread), PNG slowest (38-53 ms, libpng's deflate dominates). All four formats stay under 55 ms at 1080p on one thread.

These numbers reflect the optimization series in v1.1.x (allocation-free SVG number formatting, glyph outline cache, opaque-detect un-premultiply with SSSE3/NEON shuffle, deferred text overlays, larger FT raster pool); see [`optimization.md`](optimization.md) for the per-finding breakdown.

Repro the numbers locally:

```
php -d extension=./modules/fastchart.so docs/bench/bench.php
```

Iteration count via `FC_BENCH_ITERS` (default 50). Bench source at [`docs/bench/bench.php`](docs/bench/bench.php).

What you can render
-------------------

[](#what-you-can-render)

26 chart classes plus a 2-class symbology family, all under the `FastChart\` namespace. Each name links to its rendered example image:

- **Cartesian:** [`LineChart`](docs/examples/01_line_basic.png), [`AreaChart`](docs/examples/27a_area_stacked.png), [`BarChart`](docs/examples/03_bar_grouped.png) (vertical, horizontal, stacked, grouped, floating, layered), [`ScatterChart`](docs/examples/06_scatter_trend.png), [`BubbleChart`](docs/examples/14_bubble.png).
- **Financial:** [`StockChart`](docs/examples/07_stock_candle_ma.png)with seven candle styles (`STYLE_CANDLE`, `STYLE_BAR`, `STYLE_DIAMOND`, `STYLE_I_CAP`, `STYLE_HOLLOW`, `STYLE_VOLUME`, `STYLE_VECTOR`), SMA / EMA / WMA overlays, optional volume pane and custom indicator panes (RSI, MACD, Bollinger, OBV, stochastic, PSAR).
- **Non-Cartesian:** [`RadarChart`](docs/examples/08_radar.png), [`PolarChart`](docs/examples/16_polar.png), [`SurfaceChart`](docs/examples/15a_surface.png), [`ContourChart`](docs/examples/15b_contour.png).
- **Specialised:** [`PieChart`](docs/examples/05_pie_donut.png) (with optional donut hole + leader lines), [`GaugeChart`](docs/examples/10_gauge.png), [`LinearMeter`](docs/examples/36a_linear_meter_horizontal.png), [`GanttChart`](docs/examples/17_gantt.png), [`BoxPlot`](docs/examples/09_boxplot.png), [`Treemap`](docs/examples/32_treemap.png), [`Funnel`](docs/examples/33_funnel.png), [`Waterfall`](docs/examples/34_waterfall.png), [`Heatmap`](docs/examples/35_heatmap.png), [`BulletChart`](docs/examples/43_bullet.png), [`ParetoChart`](docs/examples/44_pareto.png), [`CalendarHeatmap`](docs/examples/45_calendar_heatmap.png).
- **Hierarchical / flow:**[`SunburstChart`](docs/examples/46_sunburst.png), [`SankeyChart`](docs/examples/47_sankey.png), [`MarimekkoChart`](docs/examples/48_marimekko.png), [`VectorChart`](docs/examples/49_vector.png).
- **Symbology:** [`Code128`](docs/examples/41a_code128_alphanumeric.png)(1D barcode, ISO/IEC 15417, auto-switching A/B/C subsets, optional human-readable text), [`QrCode`](docs/examples/42b_qrcode_ecc_m.png)(2D matrix code, ISO/IEC 18004, ECC L/M/Q/H, versions 1..40).

Cross-cutting features available on most chart types:

- TrueType / OpenType labels via `setFontPath()` (and per-role `setTitleFont()`, `setAxisFont()`, `setLabelFont()`).
- Light and dark themes (`THEME_LIGHT`, `THEME_DARK`); per-series colors via `setSeriesColors()`; full custom palettes via `setPalette()`.
- Legend positioning (`LEGEND_TOP_RIGHT`, `_TOP_LEFT`, `_BOTTOM_RIGHT`, `_BOTTOM_LEFT`, `_NONE`).
- Annotations: plot bands, vertical bands, horizontal / vertical lines, text labels, icon plots, error bars, zones.
- Strict-mode input validation (`setStrict(true)` rejects malformed series with a `TypeError` instead of silently coercing to NaN).
- Background images, drop shadows, anti-aliased lines and markers.
- Image map output (`getImageMap()` returns category-aligned rectangles for HTML overlay).

Examples
--------

[](#examples)

A gallery of code + rendered chart pairs lives in [`docs/README.md`](docs/README.md). Forty-two runnable scripts in [`docs/examples/`](docs/examples/) regenerate the images and exercise every public method on the API surface.

Public classes
--------------

[](#public-classes)

All under the `FastChart\` namespace:

- `Chart`: abstract base. Carries shared geometry / theme / font / legend / annotation setters, the `version()` static, and the chart- family enums (themes, candle styles, legend positions, line styles, marker styles, MA kinds).
- `LineChart`, `AreaChart`, `BarChart`, `ScatterChart`, `BubbleChart`: series-based plots.
- `PieChart`: slice-based, with optional donut hole.
- `StockChart`: OHLC(V) candlesticks, moving-average overlays, volume + indicator panes.
- `RadarChart`, `PolarChart`, `SurfaceChart`, `ContourChart`: non-Cartesian plots.
- `GaugeChart`, `LinearMeter`: single-value readouts with zoned ranges.
- `GanttChart`: time-axis task bars with dependency links and milestones.
- `BoxPlot`: five-number summaries with per-category outliers.
- `Treemap`, `Funnel`, `Waterfall`: value-encoded layouts (rectangle packing, stage drop-off, signed-delta running totals). `Funnel`supports a triangle-with-bands layout via `setStyle(STYLE_PYRAMID)`for callers who want the classic pyramid shape.
- `Heatmap`: 2D grid with linear color-ramp interpolation.

Every setter returns `static`, so a single fluent expression configures and emits a chart.

The Symbol family lives parallel to `Chart` (no shared base, since axes / palettes / plot rect have no meaning for a barcode):

- `Symbol`: abstract base for all 1D + 2D codes. Carries shared setters: `setSize()`, `setData()`, `setQuietZone()`, `setForeground()`, `setBackground()`, `setTransparentBackground()`, `setDpi()`, `setSvgTextMode()`, `setJpegQuality()`, plus the same `renderPng()`/ `renderJpeg()` / `renderWebp()` / `renderSvg()` / `drawSvgFragment()` / `renderToFile()` helpers as `Chart`. Reload via `imagecreatefromstring()` to composite onto an existing canvas.
- `Barcode`: abstract 1D linear-barcode base.
- `Code128` (extends `Barcode`): ISO/IEC 15417, alphanumeric, three subsets (A: control + uppercase, B: full ASCII printable, C: digit pairs). Auto-switches between subsets to minimise encoded length; mod-103 checksum appended automatically. `setShowText(true)`renders the human-readable payload below the bars using the auto-detected default font.
- `QrCode` (extends `Symbol`): ISO/IEC 18004, four error-correction levels (`ECC_L` ~7%, `ECC_M` ~15%, `ECC_Q` ~25%, `ECC_H` ~30%), versions 1..40. Encoder is the vendored nayuki/QR-Code-generator C library. `setMinVersion()` / `setMaxVersion()` pin the symbol size; the encoder picks the smallest version that fits within the range. Input must be valid UTF-8.

🔗 PHP Performance Toolkit
-------------------------

[](#-php-performance-toolkit)

Companion native PHP extensions for high-throughput PHP workloads:

- **[php\_excel](https://github.com/iliaal/php_excel)**: native Excel I/O. 7-10× faster than PhpSpreadsheet, full XLS/XLSX with formulas, formatting, and styling. Powered by LibXL.
- **[mdparser](https://github.com/iliaal/mdparser)**: native CommonMark + GFM parser. 15-30× faster than pure-PHP alternatives, full CommonMark 0.31 compliance.
- **[php\_clickhouse](https://github.com/iliaal/php_clickhouse)**: native ClickHouse client speaking the wire protocol directly. Picks up where SeasClick left off.

License
-------

[](#license)

BSD 3-Clause for the extension itself; see [`LICENSE`](LICENSE). Vendored third-party code (all MIT):

- `vendor/plutovg/`: Samuel Ugochukwu's [plutovg](https://github.com/sammycage/plutovg) 2D rasterizer. See [`vendor/plutovg/LICENSE`](vendor/plutovg/LICENSE).
- `vendor/plutosvg/`: Samuel Ugochukwu's [plutosvg](https://github.com/sammycage/plutosvg) SVG document parser. See [`vendor/plutosvg/LICENSE`](vendor/plutosvg/LICENSE).
- `vendor/qrcodegen/`: nayuki's [QR-Code-generator](https://github.com/nayuki/QR-Code-generator)(C variant). See [`vendor/qrcodegen/LICENSE`](vendor/qrcodegen/LICENSE).

SPDX: `(BSD-3-Clause AND MIT)`.

---

[Follow @iliaa on X](https://x.com/iliaa) • [Blog](https://ilia.ws/blog/fastchart-1-x-why-i-rewrote-it-after-0-2-release) • If this saved you a chart-rendering microservice, ⭐ star it!

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance98

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

8

Last Release

19d ago

Major Versions

0.2.0 → 1.0.02026-05-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2838354?v=4)[iliaa](/maintainers/iliaa)[@iliaa](https://github.com/iliaa)

---

Top Contributors

[![iliaal](https://avatars.githubusercontent.com/u/158724?v=4)](https://github.com/iliaal "iliaal (228 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![henderkes](https://avatars.githubusercontent.com/u/7896469?v=4)](https://github.com/henderkes "henderkes (1 commits)")

---

Tags

barcodechartchartscode128graphgraphicsphpphp-extensionqrcodesvgvisualizationqrcodesvgbarcodechartgraphgaugebulletphp-extensiontreemappievisualizationganttpolarradarheatmapsurfacewaterfallfunnelcandlestickohlcvtechnical-indicatorscontourboxplotparetosunburstsankeymarimekko

### Embed Badge

![Health badge](/badges/iliaal-fastchart/health.svg)

```
[![Health](https://phpackages.com/badges/iliaal-fastchart/health.svg)](https://phpackages.com/packages/iliaal-fastchart)
```

###  Alternatives

[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k27.4M108](/packages/picqer-php-barcode-generator)[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k14.0M51](/packages/milon-barcode)[samchristy/piechart

A simple class for drawing pie charts with ImageMagick or GD in PHP.

3447.9k1](/packages/samchristy-piechart)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
