PHPackages                             noki/laravel-php-graph - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. noki/laravel-php-graph

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

noki/laravel-php-graph
======================

PHP Graphing Library that creates graphs in Laravel

v1.0.1(7mo ago)04MITPHPPHP ^7.0 || ^8.0

Since Sep 17Pushed 7mo agoCompare

[ Source](https://github.com/novakurosevic/laravel-php-graph)[ Packagist](https://packagist.org/packages/noki/laravel-php-graph)[ Docs](https://github.com/novakurosevic/laravel-php-graph)[ RSS](/packages/noki-laravel-php-graph/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

Laravel PHP Graph Lib
=====================

[](#laravel-php-graph-lib)

📜 History of PHP Graph Lib
--------------------------

[](#-history-of-php-graph-lib)

The first version of PHP Graph Lib was created by [Elliott Brueggeman](https://github.com/elliottb) in late 2007 🙂 — almost 20 years ago! Good things really do stand the test of time.

You can thank [Elliott Brueggeman](https://github.com/elliottb) by giving stars to his repositories or following him. Remember, he created this library under the MIT License and made it freely available. Today, it remains one of the best PHP libraries for creating graphs and pie charts under the MIT License.

Since 2007 and the first version of this library PHP versions have changed and so the library evolved. Current version is compatible with PHP 8.2.

Current repo is forked from [repository](https://github.com/Troopster19/PhpGraph) of [Troopster19](https://github.com/Troopster19/PhpGraph) and at the moment of forking code was under MIT licence.

❓ What does this package do?
----------------------------

[](#-what-does-this-package-do)

This package allows you to create graph and pie chart images. You have several options for handling images, including:

- Displaying image from php memory
- Save image to storage in Laravel and later handle that image
- Save image to public directory in Laravel. This way you have public access to this image. This package provides URL for public images.

Warning

### **Why Check Out This Package**

[](#why-check-out-this-package)

1. Few Laravel packages provide both graph and chart generation **plus** image export support.
2. It’s lightweight, easy to integrate, and released under the MIT license for full flexibility.

---

🚀 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 9
- PHP Extensions:
    - [GD library](https://www.php.net/manual/en/book.image.php) (`ext-gd`)

### Composer Installation

[](#composer-installation)

```
composer require noki/laravel-php-graph
```

⚙️ PHP GD Extension Setup
-------------------------

[](#️-php-gd-extension-setup)

### Linux (Debian/Ubuntu)

[](#linux-debianubuntu)

```
sudo apt-get update
sudo apt-get install php-gd
```

> Example for PHP 8.3 — be sure to use the correct package names:

First, check your PHP version:

```
php -v
```

Then install GD for your version:

```
sudo apt-get install php8.3-gd
```

To verify if GD is installed:

```
php -m | grep gd
```

---

### macOS (with Homebrew)

[](#macos-with-homebrew)

```
brew install php
# OR, if PHP is already installed:
brew reinstall php
```

> The GD extension (`gd`) is bundled with PHP on macOS. No extra installation is usually required.

To confirm GD is enabled:

```
php -m | grep gd
```

---

### Windows

[](#windows)

1. Open your `php.ini` file.
2. Ensure the following line is **uncommented** (remove the `;` at the beginning):

```
extension=gd
```

3. Restart your web server (Apache, Nginx) or PHP-FPM.

### Verify installation

[](#verify-installation)

Run the following command to check if GD is enabled:

```
php -m | findstr gd
```

---

📦 Usage
-------

[](#-usage)

### Namespace

[](#namespace)

```
use Noki\PhpGraph\Graph;
```

---

### 1. Create a private graph (not publicly accessible)

[](#1-create-a-private-graph-not-publicly-accessible)

```
        $data = array(
            12124,
            5535,
            43373,
            22223,
            90432,
            23332,
            15544,
            24523,
            32778,
            38878,
            28787,
            33243,
            34832,
            32302
        );

        $graph = new Graph(500, 350);

        $graph->setTitle('Widgets Produced');
        $graph->setGradient('red', 'maroon');
        $graph->addData($data);
        $file_path = $graph->createGraph('my_file_name' ,'F');
```

With line

```
$file_path = $graph->createGraph('my_file_name' ,'F');
```

it is set file name without extension or directory root. Parameter 'F' is used for output to file. This file will be saved in **storage/app/private/php-graph-data** directory inside Laravel.

File will be saved at that route and in variable **$file\_path** will be set route to graph image.

> **Important notes:**
>
> 1. Only ASCII codes are allowed in texts in PHP Graph Lib.
> 2. Since the output image format is always **PNG**, you **do not need to set a file extension** — any extension you provide will be ignored and `.png` will be automatically added.
>
> Also, if you include a directory path in the file name, it will be removed, because **all images are saved in the `storage/app/private/php-graph-data` directory**.

---

### 2. Create a public graph (publicly accessible)

[](#2-create-a-public-graph-publicly-accessible)

Use same code as above for graph drawing just change last line

```
$file_url = $graph->createGraph('my_file_name' ,'U');
```

This way image will be saved to **public/images/php-graph-data/** directory. This image will be publicly accessible. In variable **$file\_url** will be returned URL to this image.

> **Important note:**
>
> 1. Only ASCII codes are allowed in texts in PHP Graph Lib.
> 2. Since the output image format is always **PNG**, you **do not need to set a file extension** — any extension you provide will be ignored and `.png` will be automatically added.
>
> Also, if you include a directory path in the file name, it will be removed, because **all images are saved in the `public/images/php-graph-data` directory**.

---

### 3. Save image in PHP memory and display it without save to server

[](#3-save-image-in-php-memory-and-display-it-without-save-to-server)

This is example of creating image from Controller.

1. Create route in `routes/web.php`

```
Route::get('/testing', [TestController::class, 'testing']);
```

2. Create controller in `app/Http/TestController.php`

```
