Coder Social home page Coder Social logo

piechart's Introduction

PieChart

Latest Stable Version License Total Downloads Monthly Downloads

A reasonably efficient* class for drawing pie charts with ImageMagick or GD in PHP. Intended as a learning exercise for using the NetBeans IDE and the Xdebug profiler and debugger. The code is available under the GNU GPL v3.0, so feel free to use it with attribution. I recommend using the Imagick version, PieChartImagick over the GD version, PieChartGD.

Demonstration

Below is the code required to generate a pie chart and echo it to the client's browser. The example uses the method outputPNG() to tell the browser to render the image. Alternatively, the function forceDownloadPNG() can be used to instruct the browser to bring up the save dialog.

Documentation

View the documentation (generated with ApiGen).

Installation

Use Composer!

Example Usage

<?php
require 'vendor/autoload.php';  // Composer's autoloader.
use SamChristy\PieChart\PieChartGD;

$chart = new PieChartGD(600, 375);

$chart->setTitle('Browser Usage Statistics (January - April)');
// Method chaining coming soon!
$chart->addSlice('Google Chrome',   27, '#4A7EBB');
$chart->addSlice('Mozilla Firefox', 23, '#DA8137');
$chart->addSlice('Apple Safari',    11, '#9BBB59');
$chart->addSlice('Opera',            3, '#BE4B48');
$chart->addSlice('Other',            5, '#7D60A0');

$chart->draw();
$chart->outputPNG();

Output

Pie Chart

*This example took 150ms to execute on my laptop (i3-350M @ 2.27 GHz).

© Sam Christy 2013

piechart's People

Contributors

samchristy avatar tiagokalinke avatar warafux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

piechart's Issues

Add transparency feature

Hey, I have used this library in one of my projects and wondered if you were thinking of adding transparency to the features?

I have added it to my fork, in a really nasty and basic way; if I get time I shall work on making it an alpha transparency so it doesn't end up with nasty edges when in png mode.

Slice arcs that are larger than 180 degrees will overlap previously drawn slices

If a piechart has a large slice that takes up more than 50% of the piechart the filling of the arc shape might overlap previous slices.

It can be solved by checking if the to be drawn slice has a start and end difference > 180 in the _drawSlice function. If so I divide the slice in 2 parts and draw those using the same _drawSlice function.

Some complete graphics and some not

image

image

image

I am making a loop in several items to get the graph of each one

` $chart = new PieChartGD(450, 350);

    $chart->setTitle($questao->questaoEnunciado);

    foreach ($questao->relatorio as $x) {
        $chart->addSlice($x->resposta,$x->total,colorHEX($x->resposta));
    }
    
    $chart->draw();
    $chart->savePNG(FCPATH.'/graficos/'.$questao->questaoID.'.png');`

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.