Ti posto il codice che ho scritto io per avere un grafico riassuntivo con più array in una mia applicazione usando la stessa libreria, adattalo alle tue esigenze evedi che funziona
Codice PHP:
?php
include("phpgraphlib.php");
include("conn.php");
$graph=new PHPGraphLib(450,300);
$dataArray=array();
$sql="SELECT a.mese, b.ricavo_prev FROM mesi a, budget_generale b WHERE a.id_mese = b.id_mese ORDER BY a.id_mese ASC";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while($row = mysql_fetch_assoc($result))
{
$mese=$row["mese"];
$count=$row["ricavo_prev"];
//ADD TO ARRAY
$dataArray[$mese]=$count;
}
$dataArray2=array();
$sql="SELECT a.mese, b.costo_prev FROM mesi a, budget_generale b WHERE a.id_mese = b.id_mese ORDER BY a.id_mese ASC";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while($row = mysql_fetch_assoc($result))
{
$mese=$row["mese"];
$count=$row["costo_prev"];
//ADD TO ARRAY
$dataArray2[$mese]=$count;
}
$dataArray3=array();
$sql="SELECT a.mese, b.costo_real FROM mesi a, budget_generale b WHERE a.id_mese = b.id_mese ORDER BY a.id_mese ASC";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while($row = mysql_fetch_assoc($result))
{
$mese=$row["mese"];
$count=$row["costo_real"];
//ADD TO ARRAY
$dataArray3[$mese]=$count;
}
$graph->addData($dataArray,$dataArray2,$dataArray3);
$graph->setBackgroundColor("black");
$graph->setBarColor("white", "red", "blue");
$graph->setTitle("Budget riassuntivo");
$graph->setTitleLocation("left");
$graph->setLegend(true);
$graph->setLegendTitle("Previsto", "Pianificato", "Reale");
$graph->setTitleColor("yellow");
$graph->setupYAxis(12, "yellow");
$graph->setupXAxis(20, "yellow");
$graph->setGrid(false);
//$graph->setGoalLine(60);
//$graph->setGoalLineColor("yellow");
$graph->setBarOutlineColor("white");
$graph->setTextColor("white");
$graph->createGraph();
?>
salvalo in un file .php
poi richiamalo inserendo dove vuoi visualizzarlo col solito metodo:
Codice PHP:
<h3>Grafico Riassuntivo Annuo</h3>
[img]nomedelfilechehaisalvatoprima.php[/img]</p>
Ciao,
Fabrizio