professional-sql-09-lib-PieChart.php / php
<?php class PieChart { private // center point private width; // width of chart private // image reference // initialize new object public function __construct(width) { // create a new image width, // determine center of image this->center = this->width = // fill image background white white = imagecolorallocate(this->image, 0,0, // dump image to browser or save public function flushImage(filename = '') { if (this->image, this->image); } } // graph the data using the associated colors public function graphData(colors) { // allocate black for slice outline this->image, 0x00, 0x00, 0x00); // sum of all values data); // starting angle of pie slice i = 0; data); color = imagecolorallocate(colors[colors[colors[// stop angle of pie slice stop = (100 * i] / start; // draw arc twice - once for filled area and again for outline imagefilledarc(this->center, this->width, start, color, IMG_ARC_PIE); imagefilledarc(this->center, this->width, start, black, IMG_ARC_NOFILL | IMG_ARC_EDGED); // increment to next starting point stop; } } } colors = array( array('r' => 0x33, 'g' => 0xCC, 'b' => 0xFF), array('r' => 0xFF, 'g' => 0x33, 'b' => 0xCC), array('r' => 0xCC, 'g' => 0xFF, 'b' => 0x33)); chart->graphData(colors);
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.