Search by

ridwan / laravel-pdf-charts

Rafid Al Ridwan

A convenient Laravel wrapper for generating chart images.

Package info

github.com/rafidalridwan/laravel-pdf-charts

pkg:composer/ridwan/laravel-pdf-charts

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-09-17 11:53 UTC

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