PHP Classes

File: class.SDDinamicChart.php

Recommend this page to a friend!
  Classes of SexDev   SDDinamicChart   class.SDDinamicChart.php   Download  
File: class.SDDinamicChart.php
Role: ???
Content type: text/plain
Description: Class and example
Class: SDDinamicChart
Author: By
Last change:
Date: 23 years ago
Size: 3,849 bytes
 

Contents

Class file image Download
<?php /*------------------------------------------------------------------ | | Class SDDinamicChart | Powered by www.SexDev.com | | | Example: | <?php | $items = array( | 'Product1' => '100', | 'Product2' => '200', | 'Product3' => '300', | 'Product4' => '400', | 'Product5' => '500' | ); | $dc = new SDDinamicChart(); | $dc->sortby = SORT_DESC; | $dc->drawStats($items); | ?> ------------------------------------------------------------------*/ class SDDinamicChart { var $width = 600; var $sortby = SORT_ASC; var $title = 'Statistic Report'; //start positions of graph var $x = 40; var $y = 30; //right margin var $right_margin= 20; var $bar_width = 8; //colors var $def_graph_font_color = '255,255,255'; var $def_graph_percent_font_color = '255,204,0'; var $def_graph_date_font_color = '0,255,255'; var $def_graph_bgcolor = '0,64,128'; var $def_graph_bar_bgcolor = '0,0,255'; function drawStats($items = ''){ global $HTTP_GET_VARS; if(!is_array($items)) $items = $HTTP_GET_VARS; Array_multisort($items,$this->sortby); $total = 0; $max = 0; $unit = (($this->width-$this->x)-$this->right_margin) / 100; //$items= explode( "^^",$data); //calculate total foreach($items as $key => $item) { if ($item != ''){ //$pos = strlen($key); $value = $item; $total = $total + $item; } } //echo $total; exit; //var_dump($items); reset($items); //calculate height of graph $height = (sizeof($items) + 1) * ($this->bar_width + 20); Header( "Content-type: image/png"); $im = imagecreate($this->width,$height); // Allocate colors $graph_font_color=ImageColorAllocate($im,255,255,255); $graph_percent_font_color=ImageColorAllocate($im,255,204,0); $graph_date_font_color = ImageColorAllocate($im,0,255,255); $graph_bgcolor=ImageColorAllocate($im,0,64,128); $graph_bar_bgcolor=ImageColorAllocate($im,0,0,255); //background ImageFilledRectangle($im,0,0,$this->width,$height,$graph_bgcolor); //title $title_x = (imagesx($im)-7.5*strlen($this->title))/2; ImageString($im,3,$title_x,4,$this->title,$graph_font_color); //date ImageString($im,1,$this->width-285,17,'Generated by SexDev.com '.date("D M jS Y h:i:s A"),$graph_date_font_color); //line Imageline($im,$this->x,$this->y-5,$this->x,$height-15,$graph_bar_bgcolor); //draw data foreach($items as $key => $item) { if ($item != ''){ //$pos = strlen($item); $item_title = $key; $value = $item; //display percent ImageString($im,3,$this->x-25,$this->y-2,intval(round(($value/$total)*100)). "%",$graph_percent_font_color); //value right side rectangle $px = $this->x + ( intval(round(($value/$total)*100)) * $unit); //draw rectangle value ImageFilledRectangle($im,$this->x,$this->y-2,$px,$this->y+$this->bar_width,$graph_bar_bgcolor); //draw item title ImageString($im,2,$this->x+5,$this->y+9,$item_title,$graph_font_color); //draw empty rectangle ImageRectangle($im,$px+1,$this->y-2,($this->x+(100*$unit)),$this->y+$this->bar_width,$graph_bar_bgcolor); //display numbers ImageString($im,1,($this->x+(100*$unit))-40,$this->y+12,$value. "/".$total,$graph_font_color); } $this->y += $this->bar_width+20; } // Display modified image ImagePng($im); // Release allocated ressources ImageDestroy($im); } } ?>