You are here

function pChart::drawBarGraph in Visitors 7.0

Same name and namespace in other branches
  1. 8 pchart/pChart.inc \pChart::drawBarGraph()

File

pchart/pChart.inc, line 1330

Class

pChart

Code

function drawBarGraph(&$Data, &$DataDescription, $Shadow = FALSE, $Alpha = 100) {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawBarGraph", $DataDescription);
  $this
    ->validateData("drawBarGraph", $Data);
  $GraphID = 0;
  $Series = count($DataDescription["Values"]);
  $SeriesWidth = $this->DivisionWidth / ($Series + 1);
  $SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2;
  $YZero = $this->GArea_Y2 - (0 - $this->VMin) * $this->DivisionRatio;
  if ($YZero > $this->GArea_Y2) {
    $YZero = $this->GArea_Y2;
  }
  $SerieID = 0;
  foreach ($DataDescription["Values"] as $Key2 => $ColName) {
    $ID = 0;
    foreach ($DataDescription["Description"] as $keyI => $ValueI) {
      if ($keyI == $ColName) {
        $ColorID = $ID;
      }
      $ID++;
    }
    $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID;
    $XLast = -1;
    foreach ($Data as $Key => $Values) {
      if (isset($Data[$Key][$ColName])) {
        if (is_numeric($Data[$Key][$ColName])) {
          $Value = $Data[$Key][$ColName];
          $YPos = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
          if ($Shadow && $Alpha == 100) {
            $this
              ->drawRectangle($XPos + 1, $YZero, $XPos + $SeriesWidth - 1, $YPos, 25, 25, 25, TRUE, $Alpha);
          }
          $this
            ->drawFilledRectangle($XPos + 1, $YZero, $XPos + $SeriesWidth - 1, $YPos, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"], TRUE, $Alpha);
        }
      }
      $XPos = $XPos + $this->DivisionWidth;
    }
    $SerieID++;
  }
}