Charts

Charts stats

Downloads
3
Stars
20
Open Issues
0
Forks
0

View on GitHub →

SVG Charts in PHP

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 photo

Code enthusiast, Back-end developer @ Qlic Internet solutions, Freelance Developer.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Maantje Charts Related Articles

What's missing from your PHP development environment image

What's missing from your PHP development environment

Read article
Help make Filament faster! image

Help make Filament faster!

Read article
NationForge: A Self-Hosted Admin Panel for Civic Organizations image

NationForge: A Self-Hosted Admin Panel for Civic Organizations

Read article
LaraOwl: Self-Hosted Monitoring for Laravel Applications image

LaraOwl: Self-Hosted Monitoring for Laravel Applications

Read article
Blaze: An Optimized Blade Template Compiler for Laravel image

Blaze: An Optimized Blade Template Compiler for Laravel

Read article
Going Real-Time with Reverb - Laravel In Practice EP17 image

Going Real-Time with Reverb - Laravel In Practice EP17

Read article
Shift logo

Shift

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

Shift
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit