clearchart(); } function clearchart() { // Default colors unset($this->colors); // This oughta make things more readible $white['red'] = $white['green'] = $white['blue'] = 1; $black['red'] = $black['green'] = $black['blue'] = 0; $this->colors['background'] = $white; $this->colors['border'] = $black; $this->colors['hlabel'] = $black; $this->colors['vlabel'] = $black; $this->colors['vgrade'] = $black; $this->colors['hgrade'] = $black; unset($this->series); } /* Set up default colors to use globally on the chart */ function setcolor($name, $red, $green, $blue) { $this->colors[$name]['red'] = $red; $this->colors[$name]['green'] = $green; $this->colors[$name]['blue'] = $blue; } function add_series($name, $points, $color = 'black', $width = 1, $style = 'default') { $t['points'] = $points; $t['color'] = $color; $t['width'] = $width; $t['style'] = $style; $this->series[$name] = $t; } function place_chart($page, $left, $bottom, $width, $height, $type = 'line') { switch (strtolower($type)) { case 'pie' : case '3dpie' : case 'bar' : case '3dbar' : case '3dline' : case 'line' : default : $this->_place_line_chart($page, $left, $bottom, $width, $height); } } function _place_line_chart($page, $left, $bottom, $width, $height) { // First a filled rectangle to set background color $this->_fill_background($page, $left, $bottom, $width, $height); // caclulate a scale $low = $high = $numx = 0; foreach($this->series as $data) { foreach($data['points'] as $value) { if ($value < $low) $low = $value; if ($value > $high) $high = $value; } if (count($data['points']) > $numx) $numx = count($data); } if (($high - $low) <= 0) return false; $xscale = $width / $numx; $yscale = $height / ($high - $low); foreach($this->series as $data) { $a['strokecolor'] = $this->pdf->get_color($data['color']); $a['width'] = $data['width']; $c = 0; unset($x); unset($y); foreach ($data['points'] as $value) { $x[$c] = ($c * $xscale) + $left; //echo $x[$c] . " "; $y[$c] = (($value - $low) * $yscale) + $bottom; //echo $y[$c] . "
\n"; $c++; } $this->pdf->draw_line($x, $y, $page, $a); } } function _fill_background($page, $left, $bottom, $width, $height) { $a['fillcolor'] = $this->colors['background']; $a['mode'] = 'fill'; $this->pdf->draw_rectangle($bottom + $height, $left, $bottom, $left + $width, $page, $a); } } ?>