//YTD
$datay1=array($dg_data[0]['CURRENT_PERCENTAGE']*100);
//Cash Rcpt
$datay2=array($dg_data[1]['CURRENT_PERCENTAGE']*100);
//Unrestricted
$datay3=array($dg_data[2]['CURRENT_PERCENTAGE']*100);
//Participation
$datay4=array($dg_data[3]['CURRENT_PERCENTAGE']*100);
$datax=array('% of FY goal');
function cbFmtPercentage($aVal) {
return sprintf("%.1f%%",100*$aVal); // Convert to string
}
function separator1000_usd($aVal) {
return '$'.number_format($aVal);
}
// Some basic defines to specify the shape of the bar+table
$tablexpos = 50;
$rightmargin = 20;
$tableypos = 167; //add 80 to this number for height set
$nbrbar = 5;
$cellwidth = 84; // (105 former, with 4 cols) equation is width = posX + tabWidth + rightMargin
$tablewidth = $nbrbar*$cellwidth;
// Overall graph size
$height = 250; # was set at 300 but severely messed index up
$width = 480; #$tablexpos+$tablewidth+$rightmargin;
$graph = new Graph($width,$height);
$graph->SetScale("textlin");
$graph->SetMarginColor('white');
$graph->xaxis->SetPos('min');
$graph->img->SetMargin($tablexpos,$rightmargin,55,$height-$tableypos);
$graph->yaxis->HideZeroLabel();
$graph->yaxis->SetLabelFormat('%3d%%');
$graph->xaxis->SetTickLabels($datax);
$fy = $dg_data[0]['FISCAL_YEAR'];
$graph->title->Set('Dept. Goals YTD '.$fy);
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->subtitle->Set('Updated: '.$dg_data[0]['UPDATE_DATE']);
$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);
$bplot4 = new BarPlot($datay4);
#$bplot1->value->SetFormatCallback("cbFmtPercentage");
$bplot1->value->SetFormat("%3d%%");
$bplot1->value->Show();
#$bplot2->value->SetFormatCallback("cbFmtPercentage");<br />
$bplot2->value->SetFormat("%3d%%");
$bplot2->value->Show();
#$bplot3->value->SetFormatCallback("cbFmtPercentage");
$bplot3->value->SetFormat("%3d%%");
$bplot3->value->Show();
#$bplot4->value->SetFormatCallback("cbFmtPercentage");
$bplot4->value->SetFormat("%3d%%");
$bplot4->value->Show();
$bplot1->SetFillColor('orange');
$bplot2->SetFillColor("brown");
$bplot3->SetFillColor("darkgreen");
$bplot4->SetFillColor("blue");
$bplot1->SetLegend("YTD");
$bplot2->SetLegend("Cash");
$bplot3->SetLegend("UNR");
$bplot4->SetLegend("Donor");
$gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3, $bplot4));
$gbarplot->SetWidth(.9);
$graph->Add($gbarplot);
$graph->legend->SetColumns(4);
$goal_lvl = $dg_data[0]['GOAL_LEVEL'];
$data= array();
$data[]=array('', 'YTD', 'Cash', 'Unr.', '# Donors');
$curData[] = 'Current';
$goalData[] = 'Goal (lvl:'.$goal_lvl.')';
foreach ($dg_data as $key=>$value){
$curData[]=$value['FORMAT'].$value['CURRENT_VALUE'];
$goalData[]=$value['FORMAT'].$value['GOAL_VALUE'];
}
$data[] =$curData;
$data[] =$goalData;
// Setup the basic table and font
$table = new GTextTable();
$table->SetPos(-20,$tableypos+2);
$table->Set($data);
$table->SetFont(FF_ARIAL,FS_NORMAL,8.5);
// Setup default column width
$table->SetMinColWidth(92);
$table->SetMinRowHeight(20);
// Setup defalt table alignment
$table->SetAlign('center'); //, 'top');
$table->SetNumberFormat("set the formats from the array");
// Turn off border
$table->SetBorder(0);
// Turn off grid
$table->setGrid(0);
// Setup font for row 4 and 0
//$table->SetRowFont(4,FF_ARIAL,FS_BOLD,11);
$table->SetRowFont(0,FF_ARIAL,FS_BOLD,10);
// Setup color
$table->SetRowFillColor(1,'white');
$table->SetRowFillColor(2,'#f4f4f4');
#$table->SetRowFillColor(3,'orange@0.5');
$table->SetFillColor(0,1,0,4,'teal@0.8');
$table->SetRowAlign(0, 'center','top');
$table->SetColAlign(0,'right');
// Add table to the graph
$graph->Add($table);
$graph->Stroke();