3 php pdf chart generation library
4 Copyright (C) Potential Technologies 2002 - 2003
5 http://www.potentialtech.com
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 $Id: chart.class.php,v 2.2 2003/07/05 21:33:07 wmoran Exp $
27 var $colors; // global colors
28 var $series; // Array of series
29 var $pdf; // reference to the parent class
40 // This oughta make things more readible
41 $white['red'] = $white['green'] = $white['blue'] = 1;
42 $black['red'] = $black['green'] = $black['blue'] = 0;
43 $this->colors['background'] = $white;
44 $this->colors['border'] = $black;
45 $this->colors['hlabel'] = $black;
46 $this->colors['vlabel'] = $black;
47 $this->colors['vgrade'] = $black;
48 $this->colors['hgrade'] = $black;
52 /* Set up default colors to use globally on the chart
54 function setcolor($name, $red, $green, $blue)
56 $this->colors[$name]['red'] = $red;
57 $this->colors[$name]['green'] = $green;
58 $this->colors[$name]['blue'] = $blue;
61 function add_series($name, $points, $color = 'black', $width = 1, $style = 'default')
63 $t['points'] = $points;
67 $this->series[$name] = $t;
70 function place_chart($page, $left, $bottom, $width, $height, $type = 'line')
72 switch (strtolower($type)) {
80 $this->_place_line_chart($page, $left, $bottom, $width, $height);
84 function _place_line_chart($page, $left, $bottom, $width, $height)
86 // First a filled rectangle to set background color
87 $this->_fill_background($page, $left, $bottom, $width, $height);
89 $low = $high = $numx = 0;
90 foreach($this->series as $data) {
91 foreach($data['points'] as $value) {
92 if ($value < $low) $low = $value;
93 if ($value > $high) $high = $value;
95 if (count($data['points']) > $numx) $numx = count($data);
97 if (($high - $low) <= 0) return false;
98 $xscale = $width / $numx;
99 $yscale = $height / ($high - $low);
100 foreach($this->series as $data) {
101 $a['strokecolor'] = $this->pdf->get_color($data['color']);
102 $a['width'] = $data['width'];
106 foreach ($data['points'] as $value) {
107 $x[$c] = ($c * $xscale) + $left;
109 $y[$c] = (($value - $low) * $yscale) + $bottom;
110 //echo $y[$c] . "<br>\n";
113 $this->pdf->draw_line($x, $y, $page, $a);
117 function _fill_background($page, $left, $bottom, $width, $height)
119 $a['fillcolor'] = $this->colors['background'];
121 $this->pdf->draw_rectangle($bottom + $height,