PHPackages                             comecc/c-pchart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. comecc/c-pchart

ActiveProject[Image &amp; Media](/categories/media)

comecc/c-pchart
===============

Port of "pChart" library into PHP 5

2.0.4(9y ago)068GPL-3.0PHPPHP &gt;=5.5

Since Jun 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/comecc/c-pchart)[ Packagist](https://packagist.org/packages/comecc/c-pchart)[ Docs](https://github.com/comecc/c-pchart)[ RSS](/packages/comecc-c-pchart/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (6)Versions (12)Used By (0)

Table of contents:
==================

[](#table-of-contents)

- [About](#about)
- [License](#license)
- [Contributing](#contributing)
- [Installation](#installation-via-composer)
- [Usage](#usage)
    - [Draw a chart through Image class only](#draw-a-chart-through-cpimage-class-only)
    - [Draw a chart with a dedicated class](#draw-a-chart-with-a-dedicated-class)
    - [Notes](#notes)
- [Changelog](#changelog)
- [References](#references)
- [Links](#links)

About:
======

[](#about)

A project bringing Composer support and some basic PHP 5 standards to pChart 2.0 library. The aim is to allow pChart integration into modern frameworks like Symfony2.

This is the 2.0 version, which aims to further update the code, but without changing the functionality if possible. It will introduce some minor backwards compatibility breaks, so if that's a concern, use the 1.\* version.

What was done:

- Updated the supported PHP version to 5.5.
- Made a full port of the library's functionality.
- Defined and added namespaces to all classes.
- Replaced all `exit()` / `die()` commands with `throw` statements to allow a degree of error control.
- Refactored the code to meet PSR-2 standard and added annotations (as best as I could figure them out). to methods Also, typehinting was added to methods where possible, so some backwards compatibility breaks may occur.
- Added a factory service for loading the classes.
- Moved all constants to a single file `src/Resources/data/constants.php`. This file is *required*for the library to function and is now loaded via Composer.

License:
========

[](#license)

It was previously stated that this package is on [MIT](https://opensource.org/licenses/MIT) license, which did not meet the requirements set by the original author. It is now under the [GNU GPL v3](http://www.gnu.org/licenses/gpl-3.0.html)license, so if you wish to use it in a commercial project, you need to pay an [appropriate fee](http://www.pchart.net/license).

Contributing:
=============

[](#contributing)

If you wish to contribute to the `1.*` version, there is a branch called `legacy` to which you may submit pull requests. Otherwise feel free to use the `master` branch.

Installation (via Composer):
============================

[](#installation-via-composer)

For composer installation, add:

```
"require": {
    "szymach/c-pchart": "~2.0@dev"
},
```

to your composer.json file and update your dependencies. Or you can run:

```
$ composer require szymach/c-pchart
```

in your project directory, where the composer.json file is.

After that, all classes are available under `CpChart\Chart` namespace or `CpChart\Factory` for the factory.

Usage:
======

[](#usage)

Now you can autoload or use the classes via their namespaces. If you want to, you may utilize the provided factory class. Below are examples of how to use the library, the charts themselves are borrowed from the official documentation.

Draw a chart through Image class only
-------------------------------------

[](#draw-a-chart-through-image-class-only)

Not all charts need to be created through a seperate class (ex. bar or spline charts), some are created via the Image class (check the official documentation before drawing). An example for a spline chart below:

```
require __DIR__.'/../vendor/autoload.php';

use CpChart\Factory\Factory;
use Exception;

try {
    // Create a factory class - it will load necessary files automatically,
    // otherwise you will need to add them on your own
    $factory = new Factory();
    $myData = $factory->newData(array(), "Serie1");

    // Create the image and set the data
    $myPicture = $factory->newImage(700, 230, $myData);
    $myPicture->setShadow(
        true,
        array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20)
    );

    // 1st spline drawn in white with control points visible
    $firstCoordinates = array(array(40, 80), array(280, 60), array(340, 166), array(590, 120));
    $fistSplineSettings = array("R" => 255, "G" => 255, "B" => 255, "ShowControl" => true);
    $myPicture->drawSpline($firstCoordinates, $fistSplineSettings);

    // 2nd spline dashed drawn in white with control points visible
    $secondCoordinates = array(array(250, 50), array(250, 180), array(350, 180), array(350, 50));
    $secondSplineSettings = array(
        "R" => 255,
        "G" => 255,
        "B" => 255,
        "ShowControl" => true,
        "Ticks" => 4
    );
    $myPicture->drawSpline($secondCoordinates, $secondSplineSettings);

    // Output the chart to the browser
    $myPicture->Render("example.drawSpline.png");
    $myPicture->Stroke();
} catch (Exception $ex) {
    echo sprintf('There was an error: %s', $ex->getMessage());
}
```

Draw a chart with a dedicated class:
------------------------------------

[](#draw-a-chart-with-a-dedicated-class)

Some charts require using a dedicated class, which you can create via the factory. Notice that you specify the type of chart, not the class name. An example for a pie chart below:

```
require __DIR__.'/../vendor/autoload.php';

use CpChart\Chart\Pie;
use CpChart\Factory\Factory;
use Exception;

try {
    $factory = new Factory();

    // Create and populate data
    $myData = $factory->newData(array(40, 60, 15, 10, 6, 4), "ScoreA");
    $myData->setSerieDescription("ScoreA", "Application A");

    // Define the absissa serie
    $myData->addPoints(array("80"), "Labels");
    $myData->setAbscissa("Labels");

    // Create the image
    $myPicture = $factory->newImage(700, 230, $myData);

    // Draw a solid background
    $backgroundSettings = array(
        "R" => 173,
        "G" => 152,
        "B" => 217,
        "Dash" => 1,
        "DashR" => 193,
        "DashG" => 172,
        "DashB" => 237
    );
    $myPicture->drawFilledRectangle(0, 0, 700, 230, $backgroundSettings);

    //Draw a gradient overlay
    $gradientSettings = array(
        "StartR" => 209,
        "StartG" => 150,
        "StartB" => 231,
        "EndR" => 111,
        "EndG" => 3,
        "EndB" => 138,
        "Alpha" => 50
    );
    $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $gradientSettings);
    $myPicture->drawGradientArea(
        0,
        0,
        700,
        20,
        DIRECTION_VERTICAL,
        array(
            "StartR" => 0,
            "StartG" => 0,
            "StartB" => 0,
            "EndR" => 50,
            "EndG" => 50,
            "EndB" => 50,
            "Alpha" => 100
        )
    );

    // Add a border to the picture
    $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));

    // Write the picture title
    $myPicture->setFontProperties(array("FontName" => "Silkscreen.ttf", "FontSize" => 6));
    $myPicture->drawText(10, 13, "pPie - Draw 2D pie charts", array("R" => 255, "G" => 255, "B" => 255));

    // Set the default font properties
    $myPicture->setFontProperties(
        array("FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)
    );

    // Enable shadow computing
    $myPicture->setShadow(
        true,
        array("X" => 2, "Y" => 2, "R" => 150, "G" => 150, "B" => 150, "Alpha" => 100)
    );
    $myPicture->drawText(
        140,
        200,
        "Single AA pass",
        array("R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE)
    );

    // Create and draw the chart
    /* @var $pieChart CpPie */
    $pieChart = $factory->newChart("pie", $myPicture, $myData);
    $pieChart->draw2DPie(140, 125, array("SecondPass" => false));
    $pieChart->draw2DPie(340, 125, array("DrawLabels" => true, "Border" => true));
    $pieChart->draw2DPie(
        540,
        125,
        array(
            "DataGapAngle" => 10,
            "DataGapRadius" => 6,
            "Border" => true,
            "BorderR" => 255,
            "BorderG" => 255,
            "BorderB" => 255
        )
    );
    $myPicture->drawText(
        540,
        200,
        "Extended AA pass / Splitted",
        array("R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE)
    );

    // Save the chart to a test directory and output it to a browser
    $pieChart->pChartObject->Render("charts/example.draw2DPie.png");
    $pieChart->pChartObject->stroke();
} catch (Exception $ex) {
    echo sprintf('There was an error: %s', $ex->getMessage());
}
```

Notes:
------

[](#notes)

Basically, all should work as defined in the pChart 2.0 documentation with added support for try/catch functionality. The factory class has methods to load all types of classes present in the pChart library.

**IMPORTANT!** If you want to use any of the fonts or palletes files, provide only the name of the actual file, do not add the 'fonts' or 'palettes' folder to the string given into the function. If you want to load them from a different directory than the default, you need to add the full path to the file (ex. `__DIR__.'/folder/to/my/palletes`).

Changelog
=========

[](#changelog)

1.0 Stable version with basic functionality.

1.1 Added factory service.

1.1.1 Changed chart loading via factory a bit (see class annotations).

1.1.2 Updated service class with Exception handling regarding missing / wrong class name.

1.1.3 The file with classes' constants is now loaded via Composer (thanks to ThaDafinser).

1.1.4 Fixed code-breaking typ (thanks to subtronic).

1.1.5 Added an option to hide the X axis or only it's values (thanks to julien-gm).

1.1.6 Added support for closures in formatting scale (thanks to funkjedi)

2.0 Updated all classes to PSR-2 standard, added typehinting where possible, updated annotations in methods to be as accurate as possible. Added Behat testing and restructed the namespaces into more sensible structure.

References
==========

[](#references)

[The original pChart website](http://www.pchart.net/)

[Composer](https://getcomposer.org/)

PHP Framework Interoperability Group at GitHub on PHP coding standards:

[PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)

[PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)

[PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)

[PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)

Links
=====

[](#links)

[GitHub](https://github.com/szymach/c-pchart)

[Packagist](https://packagist.org/packages/szymach/c-pchart)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~89 days

Recently: every ~60 days

Total

10

Last Release

3600d ago

Major Versions

1.1.6 → 2.02015-12-24

PHP version history (2 changes)1.1.1PHP &gt;=5.3.3

2.0PHP &gt;=5.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13015520?v=4)[comecc](/maintainers/comecc)[@comecc](https://github.com/comecc)

---

Top Contributors

[![szymach](https://avatars.githubusercontent.com/u/2230556?v=4)](https://github.com/szymach "szymach (82 commits)")[![magnusjt](https://avatars.githubusercontent.com/u/5463727?v=4)](https://github.com/magnusjt "magnusjt (7 commits)")[![ThaDafinser](https://avatars.githubusercontent.com/u/533017?v=4)](https://github.com/ThaDafinser "ThaDafinser (5 commits)")[![subtronic](https://avatars.githubusercontent.com/u/1489572?v=4)](https://github.com/subtronic "subtronic (1 commits)")[![rage28](https://avatars.githubusercontent.com/u/1128700?v=4)](https://github.com/rage28 "rage28 (1 commits)")[![iansltx](https://avatars.githubusercontent.com/u/472804?v=4)](https://github.com/iansltx "iansltx (1 commits)")[![funkjedi](https://avatars.githubusercontent.com/u/9314?v=4)](https://github.com/funkjedi "funkjedi (1 commits)")

---

Tags

statisticschartspchartc-pChartCpChartcomeccpchart

###  Code Quality

TestsBehat

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/comecc-c-pchart/health.svg)

```
[![Health](https://phpackages.com/badges/comecc-c-pchart/health.svg)](https://phpackages.com/packages/comecc-c-pchart)
```

###  Alternatives

[szymach/c-pchart

Port of "pChart" library into PHP 8+

1512.6M21](/packages/szymach-c-pchart)[ianw/quickchart

QuickChart chart API

46699.0k](/packages/ianw-quickchart)[goat1000/svggraph

Generates SVG graphs

133890.0k3](/packages/goat1000-svggraph)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

12644.1k2](/packages/gravatarphp-gravatar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
