Polyscope - The agent-first dev environment for Laravel

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

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
Speeding Up Dashboards - Laravel In Practice EP16 image

Speeding Up Dashboards - Laravel In Practice EP16

Read article
Charting with Chart.js - Laravel In Practice EP15 image

Charting with Chart.js - Laravel In Practice EP15

Read article
Building a Dynamic Dashboard - Laravel In Practice EP14 image

Building a Dynamic Dashboard - Laravel In Practice EP14

Read article
JetBrains State of PHP 2025 image

JetBrains State of PHP 2025

Read article
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
Honeybadger logo

Honeybadger

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

Honeybadger
Harpoon: Next generation time tracking and invoicing logo

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
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Lucky Media logo

Lucky Media

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

Lucky Media
Shift logo

Shift

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

Shift