Giter Club home page Giter Club logo

c-pchart's Introduction

What is CpChart?

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.

What was done:

  • 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.

  • Reorganized files a bit and refactored code for better readability. Also, basic annotations were added to functions.

  • 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. It is now loaded via Composer.

Installation:

GitHub

Packagist

For composer installation, add:

"require": {

"szymach/c-pchart": "1.*"

},

to your composer.json file and update your dependencies. After that, all classes are available under "CpChart\Classes" namespace or "CpChart\Services" for the factory.

Usage:

The main difference is that you can either load the class via the 'use' statement or use the provided factory. An example below.

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

use CpChart\Services\pChartFactory;

try {
    // create a factory class - it will load necessary files automatically,
    // otherwise you will need to add them on your own
    $factory = new pChartFactory();
    
    // create and populate the pData class
    $myData = $factory->newData(array(VOID, 3, 4, 3, 5), "Serie1");

    // create the image and set the data
    $myPicture = $factory->newImage(700, 230, $myData);
    $myPicture->setGraphArea(60, 40, 670, 190);
    $myPicture->setFontProperties(
        array(
            "FontName" => "Forgotte.ttf",
            "FontSize" => 11
        )
    );
    
    // creating a pie chart - notice that you specify the type of chart, not class name.
    // not all charts need to be created through this method (ex. the bar chart),
    // some are created via the pImage class (check the documentation before drawing).
    $pieChart = $factory->newChart("pie", $myPicture, $myData);

    // do the drawing
    $myPicture->drawScale();
    $myPicture->drawSplineChart();   
    $myPicture->Stroke();

} catch (\Exception $ex) {
    echo 'There was an error: '.$ex->getMessage();
}

Basically, it 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

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).

References

The original pChart website

Composer

PHP Framework Interoperability Group at GitHub on PHP coding standards:

PSR-0

PSR-1

PSR-2

PSR-4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.