_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 BarGraphHoriz() { $maxval = $this->_maxVal; $sumval = 0; foreach ($this->_values as $value) $sumval += $value["value"]; $this->SetSortMode($this->_RowSortMode); echo '
'; foreach ($this->_values as $value) { if ($this->_ShowLabels) { if ($this->_ShowCountsMode > 0) echo ""; 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 . "
"; } echo '
'; echo ""; } $height = $this->_BarWidth; $width = @ceil(($value["value"] / $maxval) * $this->_GraphWidth); $rest_width = ($this->_GraphWidth - $width); echo '"; } echo "
'; echo '\"graph\"_BarBorderWidth . "px solid " . $this->_BarBorderColor . "\""; echo " />"; if ($rest_width > 0) { echo '\"graph\"_BarBorderWidth . "px solid " . $this->_BarBorderColor . "\""; echo " />"; } echo "
"; } } ?>