Package

Maantje Charts

SVG Charts in PHP

Package

maantje/charts

View on GitHub →

Charts - SVG Chart Rendering

Charts is a zero-dependency PHP library for generating SVG charts. It enables easy creation of SVG-based charts directly from PHP, with no additional dependencies required.

Features

  • Simple, intuitive API for chart creation
  • Lightweight, with no external dependencies
  • Supports various chart types: line charts, bar charts, stacked charts, and mixed charts
  • Fully customizable and extendable
  • Outputs pure SVG, allowing for:
    • Embedding in PDFs (ideal for reports)

Installation

To get started, install the package via composer:

composer require maantje/charts

Usage Examples

Below are some examples of the types of charts you can create using this library. Click on the links to view the source code for each example.

Simple line chart

View source

Simple bar chart

View source

Simple stacked chart

View source

Advanced line charts

View source

Advanced bar chart

View source

Mixed chart

View source

Usage

Creating a Chart

You can create different types of charts using the provided classes. Below are examples of how to create a simple bar chart and a line chart.

Simple Bar Chart
use Maantje\Charts\Bar\Bar;
use Maantje\Charts\Bar\Bars;
use Maantje\Charts\Chart;

$chart = new Chart(
    series: [
        new Bars(
            bars: [
                new Bar(name: 'Jan', value: 222301),
                new Bar(name: 'Feb', value: 189242),
                new Bar(name: 'Mar', value: 144922),
            ],
        ),
    ],
);

echo $chart->render();
Simple Line Chart
use Maantje\Charts\Chart;
use Maantje\Charts\Line\Line;
use Maantje\Charts\Line\Lines;
use Maantje\Charts\Line\Point;

$chart = new Chart(
    series: [
        new Lines(
            lines: [
                new Line(
                    points: [
                        new Point(y: 0, x: 0),
                        new Point(y: 4, x: 100),
                        new Point(y: 12, x: 200),
                        new Point(y: 8, x: 300),
                    ],
                ),
            ],
        ),
    ],
);

echo $chart->render();
Annotations

You can add annotations to your charts for better visualization.

use Maantje\Charts\Annotations\PointAnnotation;
use Maantje\Charts\YAxis;

$chart = new Chart(
    yAxis: new YAxis(
        annotations: [
            new PointAnnotation(x: 200, y: 120, label: 'Important Point'),
        ],
    ),
    // ...
);

License

The MIT License (MIT). Please see License File for more information.

Maantje Charts Related Articles

A Zero-dependency SVG Chart Library for PHP image

A Zero-dependency SVG Chart Library for PHP

Read article
Create Beautiful Charts in Filament With the Apex Charts Plugin image

Create Beautiful Charts in Filament With the Apex Charts Plugin

Read article
Livewire Charts image

Livewire Charts

Read article
Database Status Card for Laravel Pulse image

Database Status Card for Laravel Pulse

Read article
Laravel Charting Package image

Laravel Charting Package

Read article
Querying Data in MongoDB With Laravel: From Basics to Advanced Techniques image

Querying Data in MongoDB With Laravel: From Basics to Advanced Techniques

Read article

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum