You are here

function pChart::drawStackedBarGraph in Visitors 8

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

File

pchart/pChart.inc, line 1375

Class

pChart

Code

function drawStackedBarGraph(&$Data, &$DataDescription, $Alpha = 50) {

  /* Validate the Data and DataDescription array */
  $this
    ->validateDataDescription("drawBarGraph", $DataDescription);
  $this
    ->validateData("drawBarGraph", $Data);
  $GraphID = 0;
  $Series = count($DataDescription["Values"]);
  $SeriesWidth = $this->DivisionWidth * 0.8;
  $YZero = $this->GArea_Y2 - (0 - $this->VMin) * $this->DivisionRatio;
  if ($YZero > $this->GArea_Y2) {
    $YZero = $this->GArea_Y2;
  }
  $SerieID = 0;
  $LastValue = "";
  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 - $SeriesWidth / 2;
    $XLast = -1;
    foreach ($Data as $Key => $Values) {
      if (isset($Data[$Key][$ColName])) {
        if (is_numeric($Data[$Key][$ColName])) {
          $Value = $Data[$Key][$ColName];
          if (isset($LastValue[$Key])) {
            $YPos = $this->GArea_Y2 - ($Value + $LastValue[$Key] - $this->VMin) * $this->DivisionRatio;
            $YBottom = $this->GArea_Y2 - ($LastValue[$Key] - $this->VMin) * $this->DivisionRatio;
            $LastValue[$Key] += $Value;
          }
          else {
            $YPos = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
            $YBottom = $YZero;
            $LastValue[$Key] = $Value;
          }
          $this
            ->drawFilledRectangle($XPos + 1, $YBottom, $XPos + $SeriesWidth - 1, $YPos, $this->Palette[$ColorID]["R"], $this->Palette[$ColorID]["G"], $this->Palette[$ColorID]["B"], TRUE, $Alpha);
        }
      }
      $XPos = $XPos + $this->DivisionWidth;
    }
    $SerieID++;
  }
}