PHPackages                             ondrej-vrto/php-linechart - 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. ondrej-vrto/php-linechart

ActiveLibrary[Image &amp; Media](/categories/media)

ondrej-vrto/php-linechart
=========================

Generates a simple line chart in SVG format using PHP.

1.1.1(2y ago)32821[3 PRs](https://github.com/OndrejVrto/php-linechart/pulls)1MITPHPPHP ^8.1CI passing

Since Jan 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/OndrejVrto/php-linechart)[ Packagist](https://packagist.org/packages/ondrej-vrto/php-linechart)[ Docs](https://github.com/OndrejVrto/php-linechart)[ GitHub Sponsors](https://github.com/OndrejVrto)[ RSS](/packages/ondrej-vrto-php-linechart/feed)WikiDiscussions main Synced yesterday

READMEChangelog (7)Dependencies (7)Versions (13)Used By (1)

[![Social Card of PHP Line Chart](./.github/img/socialcard.png)](./.github/img/socialcard.png)

Generates a simple line chart in SVG format using PHP
=====================================================

[](#generates-a-simple-line-chart-in-svg-format-using-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/74f375db599f2b2efc670823096fb1acc00567378afd2a41f9a672a0349989db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6e6472656a2d7672746f2f7068702d6c696e6563686172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ondrej-vrto/php-linechart)[![Tests](https://camo.githubusercontent.com/6fa1d91b885d56b1d61f0b680b0aab07f4dcd205c086aaf8423aa4b14e1471c8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4f6e6472656a5672746f2f7068702d6c696e6563686172742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/OndrejVrto/php-linechart/blob/main/.github/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/6ff4e6c9456f3716337d8a87f33c20c05a90a3e7f19de70da104a04c6e9793aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6e6472656a2d7672746f2f7068702d6c696e6563686172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ondrej-vrto/php-linechart)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ondrej-vrto/php-linechart
```

Usage
-----

[](#usage)

```
$data = [0, 2, 1, 3, 3, 2, 1, 5, 4];

$svg = LineChart::new($data)->make();
```

Creates the following svg string

```

```

The generated svg looks like this.

[![](./.github/img/0.png)](./.github/img/0.png)

Input data types
----------------

[](#input-data-types)

```
$data = [0, 1, 2, 3];          // integers
$data = [0.12, 1.5555, 5.4];   // decimal numbers
$data = [true, false, true];   // booleans
$data = ["0", "002", "4.05"];  // numbers in string
$data = collect([0, 1, 2, 3]); // Illuminate\Support\Collection from Laravel
$data = [5];                   // one value => prepend zero value
$data = [];                    // empty array => set two zero value
$data = [null];                // null => set two zero value
```

It is possible to use the spread operator and insert values individually.

```
$svg = LineChart::new(0, 1, 2, 3, 4, 5)->make();
```

Example data from Laravel Eloquent query.

```
$collection = WebVisits::query()
    ->select(['day_visit_count'])
    ->whereMorphedTo('visitable', $model)
    ->orderByDesc('date')
    ->limit(365)
    ->get()
    ->pluck('day_visit_count');

$svg = LineChart::new($collection)->make();
```

Customization
-------------

[](#customization)

```
$svg = LineChart::new($data)
    ->withStrokeWidth(5)
    ->withOrderReversed()
    ->withMaxItemAmount(50)
    ->withLockYAxisRange(200)
    ->withDimensions(500, 100)
    ->withColorGradient('Green', 'Orange', 'Red')
    ->make();
```

- **`withStrokeWidth`** will determine the stroke's width
- **`withOrderReversed`** reverses the order of values
- **`withMaxItemAmount`** will determine how many values will be shown. If you originally passed on more values than this max, then the oldest ones will be omitted. If the max amount is set to a number that's *higher* than the current amount, then the graph will extended.
- **`withLockYAxisRange`** sets the maximum value of the vertical axis. This is useful if you have multiple charts that should have the same length vertical scale. By default, the maximum value is determined based on the input values.
- **`withDimensions`** will determine the width and height of the rendered SVG
- **`withColorGradient`** you can choose any number of colors. A gradient for the graph is automatically generated from them.

#### Possible color value types for method withColorGradient()

[](#possible-color-value-types-for-method-withcolorgradient)

```
    text   :  Blue, Orange, Cyan, ...
    hex    :  #0000ff, #eee, ...
    rgb    :  rgb(0, 0, 255)
    rgba   :  rgba(0, 0, 255, 1.0)
    hsl    :  hsl(240, 100%, 50%)
    hsla   :  hsla(240, 100%, 50%, 1.0)
    cmyk   :  cmyk(100%,100%,0%,0%)
    xyz    :  xyz(18.05, 7.22, 95.05)
    hsb    :  hsb(241, 100%, 50%)
    CIELab :  CIELab(32.3, 79.2, -107.86)

```

***Color gradien example:***

```
$svg = LineChart::new($data)
    ->withColorGradient('rgb(48, 231, 237)', 'rgb(0, 166, 215)', 'rgb(0, 88, 179)', 'rgb(0, 27, 135)')
    ->make();
```

[![](./.github/img/1.png)](./.github/img/1.png)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Ondrej Vrťo](https://github.com/OndrejVrto)
- [All Contributors](../../contributors)

Alternatives
------------

[](#alternatives)

- [brendt/php-sparkline](https://github.com/brendt/php-sparkline)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance57

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 67% 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 ~81 days

Recently: every ~122 days

Total

7

Last Release

769d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef50ff0349871cc35df4a7d2a2d322972942cab3f1756eb79938694b6eced489?d=identicon)[OndrejVrto](/maintainers/OndrejVrto)

---

Top Contributors

[![OndrejVrto](https://avatars.githubusercontent.com/u/32365016?v=4)](https://github.com/OndrejVrto "OndrejVrto (69 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (19 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")

---

Tags

chartspackagephp81colorsvgline-chartondrej vrtoline graph

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ondrej-vrto-php-linechart/health.svg)

```
[![Health](https://phpackages.com/badges/ondrej-vrto-php-linechart/health.svg)](https://phpackages.com/packages/ondrej-vrto-php-linechart)
```

###  Alternatives

[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[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.8k28.4M119](/packages/picqer-php-barcode-generator)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.3k453.6k30](/packages/tightenco-jigsaw)[league/color-extractor

Extract colors from an image as a human would do.

1.3k5.1M19](/packages/league-color-extractor)[ksubileau/color-thief-php

Grabs the dominant color or a representative color palette from an image.

6394.1M46](/packages/ksubileau-color-thief-php)

PHPackages © 2026

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