09/04/08 - Soporte para correos reenviados (X-Forwarded-To y X-Forwarded-For).
[xmensajitos.php.git] / libs / graphs.inc.php
blobd26d1fe762cc1597574bec107a97a1448f46b689
1 <?
2 /*
3 +-------------------------------------------------------------------+
4 | H T M L - G R A P H S (v4.4) |
5 | |
6 | Copyright Gerd Tentler www.gerd-tentler.de/tools |
7 | Created: Sep. 17, 2002 Last modified: Nov. 17, 2007 |
8 +-------------------------------------------------------------------+
9 | This program may be used and hosted free of charge by anyone for |
10 | personal purpose as long as this copyright notice remains intact. |
11 | |
12 | Obtain permission before selling the code for this program or |
13 | hosting this software on a commercial website or redistributing |
14 | this software over the Internet or in any other medium. In all |
15 | cases copyright must remain intact. |
16 +-------------------------------------------------------------------+
18 ======================================================================================================
19 Example:
21 $graph = new BAR_GRAPH("hBar");
22 $graph->values = array(234, 125, 289, 147, 190);
23 echo $graph->create();
25 Returns HTML code
26 ======================================================================================================
28 class BAR_GRAPH {
29 //----------------------------------------------------------------------------------------------------
30 // Configuration
31 //----------------------------------------------------------------------------------------------------
32 var $type = 'hBar'; // graph type: "hBar", "vBar", "pBar", or "fader"
33 var $values; // graph data: array or string with comma-separated values
35 var $graphBGColor = ''; // graph background color: string
36 var $graphBorder = ''; // graph border: string (CSS specification; doesn't work with NN4)
37 var $graphPadding = 0; // graph padding: integer (pixels)
39 var $titles; // titles: array or string with comma-separated values
40 var $titleColor = 'black'; // title font color: string
41 var $titleBGColor = '#C0E0FF'; // title background color: string
42 var $titleBorder = '2px groove white'; // title border: string (CSS specification)
43 var $titleFont = 'Arial, Helvetica'; // title font family: string (CSS specification)
44 var $titleSize = 12; // title font size: integer (pixels)
45 var $titleAlign = 'center'; // title text align: "left", "center", or "right"
46 var $titlePadding = 2; // title padding: integer (pixels)
48 var $labels; // label names: array or string with comma-separated values
49 var $labelColor = 'black'; // label font color: string
50 var $labelBGColor = '#C0E0FF'; // label background color: string
51 var $labelBorder = '2px groove white'; // label border: string (CSS specification; doesn't work with NN4)
52 var $labelFont = 'Arial, Helvetica'; // label font family: string (CSS specification)
53 var $labelSize = 12; // label font size: integer (pixels)
54 var $labelAlign = 'center'; // label text align: "left", "center", or "right"
55 var $labelSpace = 0; // additional space between labels: integer (pixels)
57 var $barWidth = 20; // bar width: integer (pixels)
58 var $barLength = 1.0; // bar length ratio: float (from 0.1 to 2.9)
59 var $barColors; // bar colors OR bar images: array or string with comma-separated values
60 var $barBGColor; // bar background color: string
61 var $barBorder = '2px outset white'; // bar border: string (CSS specification; doesn't work with NN4)
62 var $barLevelColors; // bar level colors: ascending array (bLevel, bColor[,...]); draw bars >= bLevel with bColor
64 var $showValues = 0; // show values: 0 = % only, 1 = abs. and %, 2 = abs. only, 3 = none
66 var $absValuesColor = 'black'; // abs. values font color: string
67 var $absValuesBGColor = '#C0E0FF'; // abs. values background color: string
68 var $absValuesBorder = '2px groove white'; // abs. values border: string (CSS specification; doesn't work with NN4)
69 var $absValuesFont = 'Arial, Helvetica'; // abs. values font family: string (CSS specification)
70 var $absValuesSize = 12; // abs. values font size: integer (pixels)
71 var $absValuesPrefix = ''; // abs. values prefix: string (e.g. "$")
72 var $absValuesSuffix = ''; // abs. values suffix: string (e.g. " kg")
74 var $percValuesColor = 'black'; // perc. values font color: string
75 var $percValuesFont = 'Arial, Helvetica'; // perc. values font family: string (CSS specification)
76 var $percValuesSize = 12; // perc. values font size: integer (pixels)
77 var $percValuesDecimals = 0; // perc. values number of decimals: integer
79 var $charts = 1; // number of charts: integer
81 // hBar/vBar only:
82 var $legend; // legend items: array or string with comma-separated values
83 var $legendColor = 'black'; // legend font color: string
84 var $legendBGColor = '#F0F0F0'; // legend background color: string
85 var $legendBorder = '2px groove white'; // legend border: string (CSS specification; doesn't work with NN4)
86 var $legendFont = 'Arial, Helvetica'; // legend font family: string (CSS specification)
87 var $legendSize = 12; // legend font size: integer (pixels)
89 // debug mode: false = off, true = on; just shows some extra information
90 var $debug = false;
92 // default bar colors; only used if $barColors isn't set
93 var $colors = array('#0000FF', '#FF0000', '#00E000', '#A0A0FF', '#FFA0A0', '#00A000');
95 // error messages
96 var $err_type = 'ERROR: Type must be "hBar", "vBar", "pBar", or "fader"';
98 // CSS names (don't change)
99 var $cssGRAPH = '';
100 var $cssBAR = '';
101 var $cssBARBG = '';
102 var $cssTITLE = '';
103 var $cssLABEL = '';
104 var $cssLABELBG = '';
105 var $cssLEGEND = '';
106 var $cssLEGENDBG = '';
107 var $cssABSVALUES = '';
108 var $cssPERCVALUES = '';
110 //----------------------------------------------------------------------------------------------------
111 // Class Methods
112 //----------------------------------------------------------------------------------------------------
113 function BAR_GRAPH($type = '') {
114 if($type) $this->type = $type;
117 function set_styles() {
118 if($this->graphBGColor) $this->cssGRAPH .= 'background-color:' . $this->graphBGColor . ';';
119 if($this->graphBorder) $this->cssGRAPH .= 'border:' . $this->graphBorder . ';';
120 if($this->barBorder) $this->cssBAR .= 'border:' . $this->barBorder . ';';
121 if($this->barBGColor) $this->cssBARBG .= 'background-color:' . $this->barBGColor . ';';
122 if($this->titleColor) $this->cssTITLE .= 'color:' . $this->titleColor . ';';
123 if($this->titleBGColor) $this->cssTITLE .= 'background-color:' . $this->titleBGColor . ';';
124 if($this->titleBorder) $this->cssTITLE .= 'border:' . $this->titleBorder . ';';
125 if($this->titleFont) $this->cssTITLE .= 'font-family:' . $this->titleFont . ';';
126 if($this->titleAlign) $this->cssTITLE .= 'text-align:' . $this->titleAlign . ';';
127 if($this->titleSize) $this->cssTITLE .= 'font-size:' . $this->titleSize . 'px;';
128 if($this->titleBGColor) $this->cssTITLE .= 'background-color:' . $this->titleBGColor . ';';
129 if($this->titlePadding) $this->cssTITLE .= 'padding:' . $this->titlePadding . 'px;';
130 if($this->labelColor) $this->cssLABEL .= 'color:' . $this->labelColor . ';';
131 if($this->labelBGColor) $this->cssLABEL .= 'background-color:' . $this->labelBGColor . ';';
132 if($this->labelBorder) $this->cssLABEL .= 'border:' . $this->labelBorder . ';';
133 if($this->labelFont) $this->cssLABEL .= 'font-family:' . $this->labelFont . ';';
134 if($this->labelSize) $this->cssLABEL .= 'font-size:' . $this->labelSize . 'px;';
135 if($this->labelAlign) $this->cssLABEL .= 'text-align:' . $this->labelAlign . ';';
136 if($this->labelBGColor) $this->cssLABELBG .= 'background-color:' . $this->labelBGColor . ';';
137 if($this->legendColor) $this->cssLEGEND .= 'color:' . $this->legendColor . ';';
138 if($this->legendFont) $this->cssLEGEND .= 'font-family:' . $this->legendFont . ';';
139 if($this->legendSize) $this->cssLEGEND .= 'font-size:' . $this->legendSize . 'px;';
140 if($this->legendBGColor) $this->cssLEGENDBG .= 'background-color:' . $this->legendBGColor . ';';
141 if($this->legendBorder) $this->cssLEGENDBG .= 'border:' . $this->legendBorder . ';';
142 if($this->absValuesColor) $this->cssABSVALUES .= 'color:' . $this->absValuesColor . ';';
143 if($this->absValuesBGColor) $this->cssABSVALUES .= 'background-color:' . $this->absValuesBGColor . ';';
144 if($this->absValuesBorder) $this->cssABSVALUES .= 'border:' . $this->absValuesBorder . ';';
145 if($this->absValuesFont) $this->cssABSVALUES .= 'font-family:' . $this->absValuesFont . ';';
146 if($this->absValuesSize) $this->cssABSVALUES .= 'font-size:' . $this->absValuesSize . 'px;';
147 if($this->percValuesColor) $this->cssPERCVALUES .= 'color:' . $this->percValuesColor . ';';
148 if($this->percValuesFont) $this->cssPERCVALUES .= 'font-family:' . $this->percValuesFont . ';';
149 if($this->percValuesSize) $this->cssPERCVALUES .= 'font-size:' . $this->percValuesSize . 'px;';
152 function level_color($value, $color) {
153 if($this->barLevelColors) {
154 for($i = 0; $i < count($this->barLevelColors); $i += 2) {
155 if($i+1 < count($this->barLevelColors)) {
156 if(($this->barLevelColors[$i] > 0 && $value >= $this->barLevelColors[$i]) ||
157 ($this->barLevelColors[$i] < 0 && $value <= $this->barLevelColors[$i])) {
158 $color = $this->barLevelColors[$i+1];
163 return $color;
166 function build_bar($value, $width, $height, $color) {
167 $title = $this->absValuesPrefix . $value . $this->absValuesSuffix;
168 $bg = eregi('\.(jpg|jpeg|jpe|gif|png)$', $color) ? 'background' : 'bgcolor';
169 $bar = '<table border=0 cellspacing=0 cellpadding=0><tr>';
170 $bar .= '<td style="' . $this->cssBAR . '" ' . $bg . '="' . $color . '"';
171 $bar .= ($value != '') ? ' title="' . $title . '">' : '>';
172 $bar .= '<div style="width:' . $width . 'px; height:' . $height . 'px;';
173 $bar .= ' line-height:1px; font-size:1px;"></div>';
174 $bar .= '</td></tr></table>';
175 return $bar;
178 function build_fader($value, $width, $height, $x, $color) {
179 $fader = '<table border=0 cellspacing=0 cellpadding=0><tr>';
180 $x -= round($width / 2);
181 if($x > 0) $fader .= '<td width=' . $x . '></td>';
182 $fader .= '<td>' . $this->build_bar($value, $width, $height, $color) . '</td>';
183 $fader .= '</tr></table>';
184 return $fader;
187 function build_value($val, $max_dec, $sum = 0, $align = '') {
188 $val = number_format($val, $max_dec);
189 if($sum) $sum = number_format($sum, $max_dec);
190 $value = '<td style="' . $this->cssABSVALUES . '"';
191 if($align) $value .= ' align=' . $align;
192 $value .= ' nowrap>';
193 $value .= '&nbsp;' . $this->absValuesPrefix . $val . $this->absValuesSuffix;
194 if($sum) $value .= ' / ' . $this->absValuesPrefix . $sum . $this->absValuesSuffix;
195 $value .= '&nbsp;</td>';
196 return $value;
199 function build_legend($barColors) {
200 $legend = '<table border=0 cellspacing=0 cellpadding=0><tr>';
201 $legend .= '<td style="' . $this->cssLEGENDBG . '">';
202 $legend .= '<table border=0 cellspacing=4 cellpadding=0>';
203 $l = (is_array($this->legend)) ? $this->legend : explode(',', $this->legend);
205 for($i = 0; $i < count($barColors); $i++) {
206 $legend .= '<tr>';
207 $legend .= '<td>' . $this->build_bar('', $this->barWidth, $this->barWidth, $barColors[$i]) . '</td>';
208 $legend .= '<td style="' . $this->cssLEGEND . '" nowrap>' . trim($l[$i]) . '</td>';
209 $legend .= '</tr>';
211 $legend .= '</table></td></tr></table>';
212 return $legend;
215 function build_hTitle($titleLabel, $titleValue, $titleBar) {
216 $title = '<tr>';
217 $title .= '<td style="' . $this->cssTITLE . '">' . $titleLabel . '</td>';
218 if($titleValue != '') $title .= '<td style="' . $this->cssTITLE . '">' . $titleValue . '</td>';
219 $title .= '<td style="' . $this->cssTITLE . '">' . $titleBar . '</td>';
220 $title .= '</tr>';
221 return $title;
224 function create_hBar($value, $percent, $mPerc, $mPerc_neg, $max_neg, $mul, $valSpace, $bColor, $border, $spacer, $spacer_neg) {
225 $bar = '<table border=0 cellspacing=0 cellpadding=0 height=100%><tr>';
227 if($percent < 0) {
228 $percent *= -1;
229 $bar .= '<td style="' . $this->cssLABELBG . '" height=' . $this->barWidth . ' width=' . round(($mPerc_neg - $percent) * $mul + $valSpace) . ' align=right nowrap>';
230 if($this->showValues < 2) $bar .= '<span style="' . $this->cssPERCVALUES . '">' . number_format($percent, $this->percValuesDecimals) . '%</span>';
231 $bar .= '&nbsp;</td><td style="' . $this->cssLABELBG . '">';
232 $bar .= $this->build_bar($value, round($percent * $mul), $this->barWidth, $bColor);
233 $bar .= '</td><td width=' . $spacer . '></td>';
235 else {
236 if($max_neg) {
237 $bar .= '<td style="' . $this->cssLABELBG . '" width=' . $spacer_neg . '>';
238 $bar .= '<table border=0 cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>';
240 if($percent) {
241 $bar .= '<td>';
242 $bar .= $this->build_bar($value, round($percent * $mul), $this->barWidth, $bColor);
243 $bar .= '</td>';
245 else $bar .= '<td><img width=1 height=' . ($this->barWidth + ($border * 2)) . '></td>';
246 $bar .= '<td style="' . $this->cssPERCVALUES . '" width=' . round(($mPerc - $percent) * $mul + $valSpace) . ' align=left nowrap>';
247 if($this->showValues < 2) $bar .= '&nbsp;' . number_format($percent, $this->percValuesDecimals) . '%';
248 $bar .= '&nbsp;</td>';
250 $bar .= '</tr></table>';
252 return $bar;
255 function create_vBar($value, $percent, $mPerc, $mPerc_neg, $max_neg, $mul, $valSpace, $bColor, $border, $spacer, $spacer_neg) {
256 $bar = '<table border=0 cellspacing=0 cellpadding=0 width=100%><tr align=center>';
258 if($percent < 0) {
259 $percent *= -1;
260 $bar .= '<td height=' . $spacer . '></td></tr><tr align=center valign=top><td style="' . $this->cssLABELBG . '">';
261 $bar .= $this->build_bar($value, $this->barWidth, round($percent * $mul), $bColor);
262 $bar .= '</td></tr><tr align=center valign=top>';
263 $bar .= '<td style="' . $this->cssLABELBG . '" height=' . round(($mPerc_neg - $percent) * $mul + $valSpace) . ' nowrap>';
264 $bar .= ($this->showValues < 2) ? '<span style="' . $this->cssPERCVALUES . '">' . number_format($percent, $this->percValuesDecimals) . '%</span>' : '&nbsp;';
265 $bar .= '</td>';
267 else {
268 $bar .= '<td style="' . $this->cssPERCVALUES . '" valign=bottom height=' . round(($mPerc - $percent) * $mul + $valSpace) . ' nowrap>';
269 if($this->showValues < 2) $bar .= number_format($percent, $this->percValuesDecimals) . '%';
270 $bar .= '</td>';
271 if($percent) {
272 $bar .= '</tr><tr align=center valign=bottom><td>';
273 $bar .= $this->build_bar($value, $this->barWidth, round($percent * $mul), $bColor);
274 $bar .= '</td>';
276 else $bar .= '</tr><tr><td><img width=' . ($this->barWidth + ($border * 2)) . ' height=1></td>';
277 if($max_neg) {
278 $bar .= '</tr><tr><td style="' . $this->cssLABELBG . '" height=' . $spacer_neg . '>';
279 $bar .= '<table border=0 cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>';
282 $bar .= '</tr></table>';
284 return $bar;
287 function create() {
288 error_reporting(E_WARNING);
290 $this->type = strtolower($this->type);
291 $d = (is_array($this->values)) ? $this->values : explode(',', $this->values);
292 if(is_array($this->titles)) $t = $this->titles;
293 else $t = (strlen($this->titles) > 1) ? explode(',', $this->titles) : array();
294 if(is_array($this->labels)) $r = $this->labels;
295 else $r = (strlen($this->labels) > 1) ? explode(',', $this->labels) : array();
296 if($this->barColors) $drc = (is_array($this->barColors)) ? $this->barColors : explode(',', $this->barColors);
297 else $drc = array();
298 $val = $bc = array();
299 if($this->barLength < 0.1) $this->barLength = 0.1;
300 else if($this->barLength > 2.9) $this->barLength = 2.9;
301 $bars = (count($d) > count($r)) ? count($d) : count($r);
303 if($this->type == 'pbar' || $this->type == 'fader') {
304 if(!$this->barBGColor) $this->barBGColor = $this->labelBGColor;
305 if($this->labelBGColor == $this->barBGColor && count($t) == 0) {
306 $this->labelBGColor = '';
307 $this->labelBorder = '';
311 $this->set_styles();
313 $graph = '<table border=0 cellspacing=0 cellpadding=' . $this->graphPadding . '><tr>';
314 $graph .= '<td' . ($this->cssGRAPH ? ' style="' . $this->cssGRAPH . '"' : '') . '>';
316 if($this->legend && $this->type != 'pbar' && $this->type != 'fader')
317 $graph .= '<table border=0 cellspacing=0 cellpadding=0><tr valign=top><td>';
319 if($this->charts > 1) {
320 $divide = ceil($bars / $this->charts);
321 $graph .= '<table border=0 cellspacing=0 cellpadding=6><tr valign=top><td>';
323 else $divide = 0;
325 for($i = $sum = $max = $max_neg = $max_dec = $ccnt = $lcnt = $chart = 0; $i < $bars; $i++) {
326 if($divide && $i && !($i % $divide)) {
327 $lcnt = 0;
328 $chart++;
330 $drv = explode(';', $d[$i]);
332 for($j = $dec = 0; $j < count($drv); $j++) {
333 $val[$chart][$lcnt][$j] = $v = trim(str_replace(',', '.', $drv[$j]));
335 if($v > $max) $max = $v;
336 else if($v < $max_neg) $max_neg = $v;
338 if($v < 0) $v *= -1;
339 $sum += $v;
341 if(strstr($v, '.')) {
342 $dec = strlen(substr($v, strrpos($v, '.') + 1));
343 if($dec > $max_dec) $max_dec = $dec;
346 if(!$bc[$j]) {
347 if($ccnt >= count($this->colors)) $ccnt = 0;
348 $bc[$j] = (!$drc[$j] || strlen($drc[$j]) < 3) ? $this->colors[$ccnt++] : trim($drc[$j]);
351 $lcnt++;
354 $border = (int) $this->barBorder;
355 $mPerc = $sum ? round($max * 100 / $sum) : 0;
356 if($this->type == 'pbar' || $this->type == 'fader') $mul = 2;
357 else $mul = $mPerc ? 100 / $mPerc : 1;
358 $mul *= $this->barLength;
360 if($this->showValues < 2) {
361 if($this->type == 'hbar')
362 $valSpace = ($this->percValuesDecimals * ($this->percValuesSize / 1.6)) + ($this->percValuesSize * 3.2);
363 else $valSpace = $this->percValuesSize * 1.2;
365 else $valSpace = $this->percValuesSize;
366 $spacer = $maxSize = round($mPerc * $mul + $valSpace + $border * 2);
368 if($max_neg) {
369 $mPerc_neg = $sum ? round(-$max_neg * 100 / $sum) : 0;
370 $spacer_neg = round($mPerc_neg * $mul + $valSpace + $border * 2);
371 $maxSize += $spacer_neg;
374 $titleLabel = $titleValue = $titleBar = '';
376 if(count($t) > 0) {
377 $titleLabel = ($t[0] == '') ? '&nbsp;' : $t[0];
379 if($this->showValues == 1 || $this->showValues == 2) {
380 $titleValue = ($t[1] == '') ? '&nbsp;' : $t[1];
381 $titleBar = ($t[2] == '') ? '&nbsp;' : $t[2];
383 else $titleBar = ($t[1] == '') ? '&nbsp;' : $t[1];
386 for($chart = $lcnt = 0; $chart < count($val); $chart++) {
387 $graph .= '<table border=0 cellspacing=2 cellpadding=0>';
389 if($this->type == 'hbar') {
390 if(count($t) > 0) $graph .= $this->build_hTitle($titleLabel, $titleValue, $titleBar);
392 for($i = 0; $i < count($val[$chart]); $i++, $lcnt++) {
393 $label = ($lcnt < count($r)) ? trim($r[$lcnt]) : $lcnt+1;
394 $rowspan = count($val[$chart][$i]);
395 $graph .= '<tr><td style="' . $this->cssLABEL . '"' . (($rowspan > 1) ? ' rowspan=' . $rowspan : '') . '>';
396 $graph .= '&nbsp;' . $label . '&nbsp;</td>';
398 for($j = 0; $j < count($val[$chart][$i]); $j++) {
399 $percent = $sum ? $val[$chart][$i][$j] * 100 / $sum : 0;
400 $value = number_format($val[$chart][$i][$j], $max_dec);
401 $bColor = $this->level_color($val[$chart][$i][$j], $bc[$j]);
403 if($this->showValues == 1 || $this->showValues == 2)
404 $graph .= $this->build_value($val[$chart][$i][$j], $max_dec, 0, 'right');
406 $graph .= '<td' . ($this->cssBARBG ? ' style="' . $this->cssBARBG . '"' : '') . ' height=100% width=' . $maxSize . '>';
407 $graph .= $this->create_hBar($value, $percent, $mPerc, $mPerc_neg, $max_neg, $mul, $valSpace, $bColor, $border, $spacer, $spacer_neg);
408 $graph .= '</td></tr>';
409 if($j < count($val[$chart][$i]) - 1) $graph .= '<tr>';
411 if($this->labelSpace && $i < count($val[$chart])-1) $graph .= '<tr><td colspan=3 height=' . $this->labelSpace . '></td></tr>';
414 else if($this->type == 'vbar') {
415 $graph .= '<tr align=center valign=bottom>';
417 if($titleBar != '') {
418 $titleBar = str_replace('-', '-<br>', $titleBar);
419 $graph .= '<td style="' . $this->cssTITLE . '" valign=middle>' . $titleBar . '</td>';
421 for($i = 0; $i < count($val[$chart]); $i++) {
422 for($j = 0; $j < count($val[$chart][$i]); $j++) {
423 $percent = $sum ? $val[$chart][$i][$j] * 100 / $sum : 0;
424 $value = number_format($val[$chart][$i][$j], $max_dec);
425 $bColor = $this->level_color($val[$chart][$i][$j], $bc[$j]);
427 $graph .= '<td' . ($this->cssBARBG ? ' style="' . $this->cssBARBG . '"' : '') . '>';
428 $graph .= $this->create_vBar($value, $percent, $mPerc, $mPerc_neg, $max_neg, $mul, $valSpace, $bColor, $border, $spacer, $spacer_neg);
429 $graph .= '</td>';
431 if($this->labelSpace) $graph .= '<td width=' . $this->labelSpace . '></td>';
433 if($this->showValues == 1 || $this->showValues == 2) {
434 $graph .= '</tr><tr align=center>';
435 if($titleValue != '') $graph .= '<td style="' . $this->cssTITLE . '">' . $titleValue . '</td>';
437 for($i = 0; $i < count($val[$chart]); $i++) {
438 for($j = 0; $j < count($val[$chart][$i]); $j++) {
439 $graph .= $this->build_value($val[$chart][$i][$j], $max_dec);
441 if($this->labelSpace) $graph .= '<td width=' . $this->labelSpace . '></td>';
444 $graph .= '</tr><tr>';
445 if($titleLabel != '') $graph .= '<td style="' . $this->cssTITLE . '">' . $titleLabel . '</td>';
447 for($i = 0; $i < count($val[$chart]); $i++, $lcnt++) {
448 $label = ($lcnt < count($r)) ? trim($r[$lcnt]) : $lcnt+1;
449 $colspan = count($val[$chart][$i]);
450 $graph .= '<td style="' . $this->cssLABEL . '"' . (($colspan > 1) ? ' colspan=' . $colspan : '') . '>';
451 $graph .= '&nbsp;' . $label . '&nbsp;</td>';
452 if($this->labelSpace) $graph .= '<td width=' . $this->labelSpace . '></td>';
454 $graph .= '</tr>';
456 else if($this->type == 'pbar' || $this->type == 'fader') {
457 if(count($t) > 0) $graph .= $this->build_hTitle($titleLabel, $titleValue, $titleBar);
459 for($i = 0; $i < count($val[$chart]); $i++, $lcnt++) {
460 $label = ($lcnt < count($r)) ? trim($r[$lcnt]) : '';
461 $graph .= '<tr>';
463 if($label) {
464 $graph .= '<td style="' . $this->cssLABEL . '">';
465 $graph .= '&nbsp;' . $label . '&nbsp;</td>';
467 $sum = (float) $val[$chart][$i][1];
468 $percent = $sum ? $val[$chart][$i][0] * 100 / $sum : 0;
469 $value = number_format($val[$chart][$i][0], $max_dec);
471 if($this->showValues == 1 || $this->showValues == 2)
472 $graph .= $this->build_value($val[$chart][$i][0], $max_dec, $sum, 'right');
474 $graph .= '<td' . ($this->cssBARBG ? ' style="' . $this->cssBARBG . '"' : '') . '>';
476 $this->barColors = $drc[$i] ? trim($drc[$i]) : $this->colors[0];
477 $bColor = $this->level_color($val[$chart][$i][0], $this->barColors);
478 $graph .= '<table border=0 cellspacing=0 cellpadding=0><tr><td>';
479 if($this->type == 'fader') $graph .= $this->build_fader($value, round($this->barWidth / 2), $this->barWidth, round($percent * $mul), $bColor);
480 else $graph .= $this->build_bar($value, round($percent * $mul), $this->barWidth, $bColor);
481 $graph .= '</td><td width=' . round((100 - $percent) * $mul) . '></td>';
482 $graph .= '</tr></table></td>';
483 if($this->showValues < 2) $graph .= '<td style="' . $this->cssPERCVALUES . '" nowrap>&nbsp;' . number_format($percent, $this->percValuesDecimals) . '%</td>';
484 $graph .= '</tr>';
485 if($this->labelSpace && $i < count($val[$chart])-1) $graph .= '<td colspan=3 height=' . $this->labelSpace . '></td>';
488 else $graph .= '<tr><td>' . $this->err_type . '</td></tr>';
490 $graph .= '</table>';
492 if($chart < $this->charts - 1 && count($val[$chart+1])) {
493 $graph .= '</td>';
494 if($this->type == 'vbar') $graph .= '</tr><tr valign=top>';
495 $graph .= '<td>';
499 if($this->charts > 1) $graph .= '</td></tr></table>';
501 if($this->legend && $this->type != 'pbar' && $this->type != 'fader') {
502 $graph .= '</td><td width=10>&nbsp;</td><td>';
503 $graph .= $this->build_legend($bc);
504 $graph .= '</td></tr></table>';
507 if($this->debug) {
508 $graph .= "<br>sum=$sum max=$max max_neg=$max_neg max_dec=$max_dec ";
509 $graph .= "mPerc=$mPerc mPerc_neg=$mPerc_neg mul=$mul valSpace=$valSpace";
512 $graph .= '</td></tr></table>';
514 return $graph;