topical media & game development
professional-sql-09-lib-PieChart.php / php
<?php
class PieChart
{
private width; // width of chart
private width)
{
// create a new image
width, this->center = this->width = white = imagecolorallocate(this->image, 0,0, 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 = (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.