professional-sql-09-lib-BarChart.php / php
<?php class BarChart { private // width of chart private height; // height of chart private // image reference private black; // allocated color black // initialize new object public function __construct(height) { // create new image width, this->width = this->height = // fill image background white white = imagecolorallocate(this->image, 0,0, // draw axis this->black = imagecolorallocate(this->image, 20, 0, 20, this->black); imageline(height - 20, height - 20, // dump image to browser or save public function flushImage(filename = '') { if (this->image, this->image); } } // graph the data using the associated colors and labels public function graphData(colors, // start point x = 20; this->height - 20; // calculate bar width this->width - data); data); foreach (i => // calculate height of bar bar_height = (ymax) * (color = imagecolorallocate(colors[colors[colors[// draw bar twice - once for filled area and again for outline imagefilledrectangle(this->image, y, bar_width, bar_height, this->image, y, bar_width, bar_height, this->image, 2, y, i], // increment starting point x +=
(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.