_values = array(); $this->_ShowLabels = true; $this->_BarWidth = 50; $this->_GraphWidth = 360; //$this->_BarImg = ""; //$this->_BarImg2 = ""; $this->_BarBorderWidth = 0; $this->_BarBorderColor = "red"; $this->_ShowCountsMode = 2; $this->_RowSortMode = 1; $this->_TDClassHead = "grphh"; $this->_TDClassLabel = "grph"; $this->_TDClassCount = "grphc"; $this->_GraphTitle="Graph title>"; $this->_maxVal= 100; } function SetBarBorderWidth($width) { $this->_BarBorderWidth = $width; } function SetBorderColor($color) { $this->_BarBorderColor = $color; } // mode = 1 labels asc, 2 label desc function SetSortMode($mode) { switch ($mode) { case 1: asort($this->_values); break; case 2: arsort($this->_values); break; default: break; } } function AddValue($labelName, $theValue) { array_push($this->_values, array("label" => $labelName, "value" => $theValue)); } function SetBarWidth($width) { $this->_BarWidth = $width; } function SetBarImg($img) { $this->_BarImg = $img; } function SetBarImg2($img) { $this->_BarImg2 = $img; } function SetShowLabels($lables) { $this->_ShowLabels = $labels; } function SetGraphWidth($width) { $this->_GraphWidth = $width; } function SetGraphTitle($title) { $this->_GraphTitle = $title; } //mode = percentage or counts function SetShowCountsMode($mode) { $this->_ShowCountsMode = $mode; } //mode = none(0) label(1) or count(2) function SetRowSortMode($sortmode) { $this->_RowSortMode = $sortmode; } function SetTDClassHead($class) { $this->_TDClassHead = $class; } function SetTDClassLabel($class) { $this->_TDClassLabel = $class; } function SetTDClassCount($class) { $this->_TDClassCount = $class; } function SetMaxVal($value) { $this->_maxVal = $value; } // function GetMaxVal() { // $maxval = 0; // foreach($this->_values as $value) if($maxval<$value["value"]) $maxval = $value["value"]; // return $maxval; // } function BarGraphHoriz() { //$maxval = $this->GetMaxVal(); $maxval = $this->_maxVal; foreach($this->_values as $value) $sumval += $value["value"]; $this->SetSortMode($this->_RowSortMode); echo ""; foreach($this->_values as $value) { if ($this->_ShowLabels) { echo ""; echo ""; } echo ""; //echo ""; } $height = $this->_BarWidth; //$width=ceil($value["value"]*$this->_GraphWidth/$maxval); $width=ceil(($value["value"]/$maxval)*$this->_GraphWidth); $rest_width=($this->_GraphWidth-$width); echo '"; } echo "
_TDClassLabel."\""; if ($this->_ShowCountsMode>0) echo " colspan=\"2\""; if ($this->_ShowCountsMode>0) { switch ($this->_ShowCountsMode) { case 1: $count = round(100*$value["value"]/$sumval)."%"; break; case 2: $count = $value["value"]; break; /* Exit the switch and the while. */ default: break; } echo ">".$value["label"]." ".$count."
$count
'; echo '\"graph\"_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; echo " />"; if ($rest_width>0) { echo '\"graph\"_BarBorderWidth."px solid ".$this->_BarBorderColor."\""; echo " />"; } echo "
"; } } ?>