ridwan / laravel-pdf-charts
A convenient Laravel wrapper for generating chart images.
Requires
- php: ^8.0
- illuminate/http: ^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-18 03:49:55 UTC
README
Generate beautiful, server-side chart images and PDFs in Laravel using Chart.js-style configurations โ without requiring a browser or external chart service in your Laravel application.
โจ Features
- ๐ Generate charts directly from Laravel
- ๐งฉ Chart.js-style configuration
- ๐ผ๏ธ Export charts as PNG, SVG, WebP, or PDF
- โก Server-side rendering
- ๐จ Custom chart dimensions and background colors
- ๐ Configurable device pixel ratio
- ๐ Support for Chart.js versions
- ๐พ Save generated charts directly to disk
- ๐ข Generate Base64 or Data URI representations
- ๐งฑ Fluent API
- ๐ Laravel dependency injection support
- ๐ฆ Simple Composer installation
- ๐ชถ No browser required in your Laravel application
๐ฆ Installation
Install the package using Composer:
composer require ridwan/laravel-pdf-charts
Publish Configuration
Publishing the configuration file is optional:
php artisan vendor:publish --tag=pdf-charts-config
After publishing, you can customize the package configuration according to your application's requirements.
๐ Quick Start
Import the Chart facade:
use Ridwan\LaravelPdfCharts\Facades\Chart;
Then create a chart using a Chart.js-style configuration:
$image = Chart::make([ 'type' => 'bar', 'data' => [ 'labels' => ['Jan', 'Feb', 'Mar'], 'datasets' => [ [ 'label' => 'Sales', 'data' => [120, 180, 150], ], ], ], ])->render();
The generated chart is returned as binary output, which you can use in your Laravel application.
๐ Supported Charts
The package supports the following chart types:
| Type | Description |
|---|---|
bar |
Vertical or horizontal bars for comparing values |
line |
Connected points for displaying trends |
pie |
Circular segments representing parts of a whole |
doughnut |
Pie chart with a cut-out center |
radar |
Multi-axis spider/web chart for comparing variables |
polarArea |
Circular segments where angle and radius represent values |
scatter |
Individual (x, y) points for correlation or distribution |
bubble |
Scatter-style chart with radius representing a third dimension |
You can also create mixed charts by specifying different chart types for individual datasets.
๐ Chart Examples
Bar Chart
Chart::make([ 'type' => 'bar', 'data' => [ 'labels' => ['Jan', 'Feb', 'Mar'], 'datasets' => [ [ 'label' => 'Sales', 'data' => [120, 180, 150], ], ], ], ])->render();
Line Chart
Chart::make([ 'type' => 'line', 'data' => [ 'labels' => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], 'datasets' => [ [ 'label' => 'Visitors', 'data' => [12, 19, 8, 15, 22], 'fill' => false, ], ], ], ])->render();
Pie Chart
Chart::make([ 'type' => 'pie', 'data' => [ 'labels' => ['Red', 'Blue', 'Yellow'], 'datasets' => [ [ 'data' => [300, 50, 100], ], ], ], ])->render();
Doughnut Chart
Chart::make([ 'type' => 'doughnut', 'data' => [ 'labels' => ['Desktop', 'Mobile', 'Tablet'], 'datasets' => [ [ 'data' => [55, 35, 10], ], ], ], ])->render();
Radar Chart
Chart::make([ 'type' => 'radar', 'data' => [ 'labels' => [ 'Speed', 'Power', 'Range', 'Durability', 'Accuracy', ], 'datasets' => [ [ 'label' => 'Player A', 'data' => [65, 59, 90, 81, 56], ], ], ], ])->render();
Polar Area Chart
Chart::make([ 'type' => 'polarArea', 'data' => [ 'labels' => [ 'Red', 'Green', 'Yellow', 'Grey', 'Blue', ], 'datasets' => [ [ 'data' => [11, 16, 7, 3, 14], ], ], ], ])->render();
Scatter Chart
Scatter charts use objects containing x and y values:
Chart::make([ 'type' => 'scatter', 'data' => [ 'datasets' => [ [ 'label' => 'Scatter Dataset', 'data' => [ ['x' => -10, 'y' => 0], ['x' => 0, 'y' => 10], ['x' => 10, 'y' => 5], ], ], ], ], ])->render();
Bubble Chart
Bubble charts support an additional r value representing the bubble radius:
Chart::make([ 'type' => 'bubble', 'data' => [ 'datasets' => [ [ 'label' => 'Bubbles', 'data' => [ ['x' => 20, 'y' => 30, 'r' => 15], ['x' => 40, 'y' => 10, 'r' => 10], ['x' => 30, 'y' => 20, 'r' => 25], ], ], ], ], ])->render();
๐ ๏ธ Fluent API
Customize the generated chart using the fluent API:
$image = Chart::make($config) ->width(800) ->height(400) ->format('png') ->backgroundColor('white') ->devicePixelRatio(2) ->version('4') ->render();
Available Options
| Method | Description |
|---|---|
width(800) |
Set chart width |
height(400) |
Set chart height |
format('png') |
Set output format |
backgroundColor('white') |
Set chart background |
devicePixelRatio(2) |
Configure rendering pixel density |
version('4') |
Specify Chart.js version |
render() |
Generate the chart |
Supported Formats
png
svg
webp
pdf
For example:
$chart = Chart::make($config) ->width(1200) ->height(600) ->format('png') ->render();
๐ข Base64 & Data URI
Generate a Base64 representation of the chart:
$dataUri = Chart::make($config)->toBase64();
By default, the result can be returned as a Data URI.
If you only need the raw Base64 content:
$raw = Chart::make($config) ->toBase64(dataUri: false);
This can be useful when embedding charts into HTML, emails, APIs, or other documents.
๐พ Save Charts to Disk
Save the generated chart directly to a file:
$path = Chart::make($config) ->save(storage_path('app/charts/sales.png'));
You can also select the desired format before saving:
$path = Chart::make($config) ->format('pdf') ->save(storage_path('app/charts/sales.pdf'));
๐๏ธ How It Works
The package follows a simple rendering flow:
โโโโโโโโโโโโโโโโโโโโโโโ
โ Laravel App โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ridwan/laravel-pdf-charts โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Chart Configuration โ
โ Chart.js Style โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Chart Renderer โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PNG / SVG / WebP / PDF โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The goal is to keep chart generation inside your Laravel application while exposing a simple PHP API.
๐ License
This package is open-sourced software licensed under the MIT License.
See the LICENSE file for more information.
โญ Support
If this package helps you build better Laravel applications, consider giving the repository a โญ on GitHub.
Your feedback, issues, and contributions are also welcome.
๐ฆ Package
Package: ridwan/laravel-pdf-charts
Purpose: Server-side chart generation for Laravel
Output formats: PNG ยท SVG ยท WebP ยท PDF
Chart configuration: Chart.js-style
License: MIT