DbHandle)) { $imgwidth=900; $imgheight=500; $fontsize=10; $topmargin=50; $bottommargin=90+count($standort1)*10; $leftmargin=80; $rightmargin=30; $barwidth=0.6; $barmargin=(1-$barwidth)/2-0.04; $barFill=array("#1b5c85","#a6d1f7", "#d9f6ff"); //Klasse für die vertikalen Linien, die die verschiedenen Regionen unter der x-Achse abgrenzen class RegionalAxisPlotLine extends PlotLine{ function Stroke($aImg,$aXScale,$aYScale) { $aImg->SetColor($this->color); $aImg->SetLineWeight($this->weight); $ymin_abs=$aYScale->Translate($aYScale->GetMinVal())+60; $ymax_abs=$aYScale->Translate($aYScale->GetMinVal()); $xpos_abs=$aXScale->Translate($this->scaleposition); $aImg->Line($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs); } } //Klasse für die vertikalen Linien, die die verschiedenen Flächen unter der x-Achse abgrenzen class PlacAxisPlotLine extends PlotLine{ function Stroke($aImg,$aXScale,$aYScale) { $aImg->SetColor($this->color); $aImg->SetLineWeight($this->weight); $ymin_abs=$aYScale->Translate($aYScale->GetMinVal())+30; $ymax_abs=$aYScale->Translate($aYScale->GetMinVal()); $xpos_abs=$aXScale->Translate($this->scaleposition); $aImg->Line($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs); } } foreach ($standort1 as $standort){ $standorte[]=$Db->String("select distinct standort from waldner.depoqac where standort='".$standort."' order by standort desc"); } rsort($standorte); $sql="select * from waldner.prodreg order by code asc"; // echo $sql; $Stmt = $Db->Parse($sql); $Db->Exec($Stmt); $regions = $Db->GetData($Stmt, OCI_ASSOC + OCI_RETURN_NULLS); $n=count($regions); if ($n>0) { $region=0; $totalbars=0; foreach($regions as $region_i) {//Loop über Regionen $region+=1; $regionalbars[$region]=0; $places=$Db->RowArray("select plac from waldner.depo_plots where prodreg=".$region_i['CODE']." order by pos"); foreach($places as $place_i){//Loop über Flächen in jeder einzelner Region $sql="select ".implode(', ',$yvar).", standort from waldner.depoqac where annee=".$year." and plac='".$place_i['PLAC']."' and standort in ('".implode("','",$standort1)."') order by standort desc"; $Stmt = $Db->Parse($sql); $Db->Exec($Stmt); $values = $Db->GetData($Stmt, OCI_ASSOC + OCI_RETURN_NULLS); if (count($values)>0){ $standortindex=0; foreach($standorte as $standort_i){//Loop über Standorte in jeder einzelner Fläche if ($values[$standortindex]['STANDORT'] <> $standort_i){// Schreibt den Wert 0 in die Daten für das Balkendiagramm, wenn für eine Fläche nicht beide Standorte B/F vorhanden sind foreach ($yvar as $yvar_i){ $data[$standort_i][$yvar_i][]=0; } }else{ foreach ($yvar as $yvar_i){ // Schreibt den tatsächlichen Wert in die Daten für das Balkendiagramm, wenn die Daten verfügbar sind. $data[$values[$standortindex]['STANDORT']][$yvar_i][]=$values[$standortindex][$yvar_i]; } $standortindex++; } foreach($yvar as $yvar_i){ //Erstellt den Text für die Legende $legend[$standort_i][$yvar_i]=($Db->String("select TEXT_".$lang." from WALDNER.DEPO_COLUMNS where code='".strtolower($yvar_i)."'")); } } $regionalbars[$region]+=1; $axistxt[]=$place_i['PLAC']; } } $totalbars+=$regionalbars[$region]; $txt[$region] = new Text($region_i['TEXT_'.$lang.'']); $regionalline[$region] = new RegionalAxisPlotLine(VERTICAL,$totalbars-$barmargin,"black",1); } } //Nach dieser Schleife sollten alle Daten im mehrdimensionalen Array $daten['STANDORT']['YVAR'] vorhanden sein. Mehrdimensional, da die Balken je nach Wunsch noch gestapelt (mehrere YVAR) oder gruppiert (mehrere STANDORTE) werden müssen if(count($yvar)>1){ $axistitle=EINTRAEGE; $graphtitle=EINTRAEGE." ".N; }else{ $axistitle=$graphtitle=$Db->String("select TEXT_".$lang." from WALDNER.DEPO_COLUMNS where code='".strtolower($yvar[0])."'"); } $axisunit=$Db->String("select UNIT_".$lang." from WALDNER.DEPO_COLUMNS where code='".strtolower($yvar[0])."'"); foreach($axistxt as $axistxt_i){ $xlabels[]=implode("\n ",array(implode(" ",$standorte),$axistxt_i)); } ///////////////////////// // Create the graph. These two calls are always required $graph = new Graph($imgwidth,$imgheight); $graph->SetScale("textlin"); $graph->SetFrame(false); $graph->SetBox(); $graph->img->SetMargin($leftmargin,$rightmargin,$topmargin,$bottommargin); if(count(array_intersect($yvar,array('QNNH4','QNNO3','QNORG_C')))>0){ $criticalNadel = new PlotBand(HORIZONTAL,BAND_SOLID,5,15,'gold2@0.5',0,DEPTH_BACK); $criticalLaub = new PlotBand(HORIZONTAL,BAND_SOLID,10,20,'orangered@0.5',0,DEPTH_BACK); $graph->AddBand($criticalLaub); $graph->AddBand($criticalNadel); } // Regional Line and Text $xsum=$leftmargin; for($a=1;$a0){ $length=($imgwidth-$leftmargin-$rightmargin)*$regionalbars[$a]/$totalbars; $txt[$a]->SetPos($xsum+$length/2, $imgheight-$bottommargin+$fontsize*3+20); $xsum+=$length; $txt[$a]->SetFont(FF_VERA,FS_BOLD,$fontsize-2); $txt[$a]->SetAlign("center"); $graph->AddText($txt[$a]); $graph->AddLine($regionalline[$a]); } } // X-Achses Lines for($a=1;$a<$totalbars;$a++){ // Line between Plots $placline[$a]=new PlacAxisPlotLine(VERTICAL,$a-$barmargin,"black",1); $graph->AddLine($placline[$a]); } // Line between Regions $firstline = new RegionalAxisPlotLine(VERTICAL,0-$barmargin,"black",1); $graph->AddLine($firstline); // Bar Plot Clusters $a=0; foreach($standorte as $standort){ $b=0; foreach($yvar as $yvar_i){ $plot[$a][$b]= new BarPlot($data[$standort][$yvar_i]); $plot[$a][$b]->SetFillColor($barFill[$b]); if (count($yvar)>1){ $plot[0][$b]->SetLegend($legend[$standort][$yvar_i]); } $b++; } if(count($yvar)>1){ $stackedplot[$a] = new AccBarPlot($plot[$a]); }else{ $stackedplot[$a] = $plot[$a][0]; } $a++; } if(count($standorte)>1){ $groupedplot = new GroupBarPlot($stackedplot); }else{ $groupedplot = $stackedplot[0]; } // ...and add it to the graph $graph->Add($groupedplot); $graph->title->Set($graphtitle." [".$axisunit."] - ".$year); $graph->title->Setmargin($topmargin/2); $graph->title->SetFont(FF_VERA,FS_BOLD,$fontsize); $graph->xgrid->Show(false,false); $graph->ygrid->Show(true); $graph->ygrid->SetColor('#f6f6f6'); $graph->ygrid->SetFill($aFlg=true,$aColor1='white',$aColor2='#f6f6f6'); $graph->yaxis->title->Set($axistitle." [".$axisunit."]"); $graph->yaxis->title->SetFont(FF_VERA,FS_BOLD,$fontsize); $graph->yaxis->title->Setmargin($leftmargin/2-10); $graph->yaxis->SetTickSide(SIDE_LEFT); $graph->yaxis->SetLabelMargin(15); $graph->yaxis->SetFont(FF_VERA); $graph->xaxis->SetTickLabels($xlabels); $graph->xaxis->HideTicks(); $graph->xaxis->SetLabelAlign('center','top','center'); $graph->xaxis->SetFont(FF_VERA,FS_NORMAL,$fontsize); $graph->legend->SetColumns(count($yvar)); $graph->legend->SetColor('black','black@1'); $graph->legend->Pos(0.5,0.98,'center','bottom'); $graph->legend->SetFillColor('white@1'); $graph->legend->SetFont(FF_VERA,FS_NORMAL,$fontsize-2); $graph->legend->SetShadow('white@1',0); // Add Contacts $txt=new Text('LWF '.date('d.m.Y',time()).', www.wsl.ch/lwf '.$contact); $txt->SetPos(5,$imgheight-12); $txt->SetFont(FF_VERA,FS_NORMAL,$fontsize-4); $graph->AddText($txt); // Display the graph $graph->Stroke(); } ?>