Código PHP:
<?php
//continuación, coloco la etiqueta <?php para que se entienda que es codigo php, pero debes quitarlaen tu archivo formado
$i=0;
do
{
$consulta="select sum(vlor) from fnnzas_entrdas where month(fcha_entrda)='$i' and year(fcha_entrda)='$anno'";
$req=mysql_query($consulta);
$row=mysql_fetch_array($req);
if($i==1)
{
$ttenero=$row[0];
}
if($i==2)
{
$ttfebrero=$row[0];
}
if($i==3)
{
$ttmarzo=$row[0];
}
if($i==4)
{
$ttabril=$row[0];
}
if($i==5)
{
$ttmayo=$row[0];
}
if($i==6)
{
$ttjunio=$row[0];
}
if($i==7)
{
$ttjulio=$row[0];
}
if($i==8)
{
$ttagosto=$row[0];
}
if($i==9)
{
$ttseptiembre=$row[0];
}
if($i==10)
{
$ttoctubre=$row[0];
}
if($i==11)
{
$ttnoviembre=$row[0];
}
if($i==12)
{
$ttdiciembre=$row[0];
}
$i++;
}while($i<13);
$i=0;
do
{
$consulta="select sum(vlor) from presupuesto_en where mes='$i' and year(fcha_entrda)='$anno'";
$req=mysql_query($consulta);
$row=mysql_fetch_array($req);
if($i==1)
{
$gtenero=$row[0]+$ttenero;
}
if($i==2)
{
$gtfebrero=$row[0]+$ttfebrero;
}
if($i==3)
{
$gtmarzo=$row[0]+$ttmarzo;
}
if($i==4)
{
$gtabril=$row[0]+$ttabril;
}
if($i==5)
{
$gtmayo=$row[0]+$ttmayo;
}
if($i==6)
{
$gtjunio=$row[0]+$ttjunio;
}
if($i==7)
{
$gtjulio=$row[0]+$ttjulio;
}
if($i==8)
{
$gtagosto=$row[0]+$ttagosto;
}
if($i==9)
{
$gtseptiembre=$row[0]+$ttseptiembre;
}
if($i==10)
{
$gtoctubre=$row[0]+$ttoctubre;
}
if($i==11)
{
$gtnoviembre=$row[0]+$ttnoviembre;
}
if($i==12)
{
$gtdiciembre=$row[0]+$ttdiciembre;
}
$i++;
}while($i<13);
}
$data1y=array($tenero,$tfebrero,$tmarzo,$tabril,$tmayo,$tjunio,$tjulio,$tagosto,$tseptiembre,$toctubre,$tnoviembre,$tdiciembre);
$data2y=array($gtenero,$gtfebrero,$gtmarzo,$gtabril,$gtmayo,$gtjunio,$gtjulio,$gtagosto,$gtseptiembre,$gtoctubre,$gtnoviembre,$gtdiciembre);
$datax=array('Ene', 'Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');
// Create the graph. These two calls are always required
$graph = new Graph(750,350,"auto");
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(100,30,20,40);
//crear leyenda
/*$graph->Legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos");*/
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillGradient("yellow","red",GRAD_VER);
$b1plot->SetWidth(20);
$b2plot = new BarPlot($data2y);
$b2plot->SetFillGradient("lightsteelblue","navy",GRAD_VER);
$b2plot->SetWidth(20);
//crear leyenda
$graph->legend->Pos(0.02,0.2,"right","center");
$b1plot->SetLegend("Gastos");
$b2plot->SetLegend("Ingresos reales + asignados");
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot));
// ...and add it to the graPH
$graph->Add($gbplot);
$graph->title->Set("RELACION GRAFICA INGRESOS - GASTOS AÑO $anno");
$graph->xaxis->title->Set("Mes");
//$graph->yaxis->SetLabelAlign("nter",'center');
$graph->yaxis->title->Set("");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetTickLabels($datax);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$txt=new Text("Valor");
$txt->Pos(10,180);
$txt->SetFont(FF_FONT1,FS_BOLD);
//$txt->SetBox('yellow','navy','gray');
$txt->SetOrientation("v");
$txt->SetColor("black");
$graph->AddText($txt);
// Display the graph
$graph->Stroke();
?>
<img src="graficas.php?ano=<?php echo $anno?>" alt="Relación gráfica ingresos - egresos ejecutados año <?php echo $anno?>">
Espero te sirva