estoy haciendo unas graficas, que se coonstruyen dependiendo del nº de resultados, va a tener mas linias o menos.. lo que hago és dibujar el gràfico, los datos de cada grafico los guardo asi:
Código PHP:
$i=0;
while($row=mysql_fetch_array($result)) // Extreu la fila resultant com una matriu associativa (clau,valor)
{
if ($i==0)
$ydataa[]= $row["milk"];
if ($i==1)
$ydatab[]= $row["milk"];
if ($i==2)
$ydatac[]= $row["milk"];
if ($i==3)
$ydatad[]= $row["milk"];
if ($i==4)
$ydatae[]= $row["milk"];
if ($i==5)
$ydataf[]= $row["milk"];
$i=$i+1;
}
el problema de hacerlo con a,b c,d etc.. es porque no puedo usar esto:$ydata.$i[]= $row["milk"]; porque me sale el mensaje del titulo ..Cannot use a scalar value as an array
Código PHP:
i=0;
while($row=mysql_fetch_array($result)) // Extreu la fila resultant com una matriu associativa (clau,valor)
{
$ydata.$i[]= $row["milk"];
$i=$i+1;
}
Código PHP:
[LEFT]
$i=0;
reset($resultwhile);//ens posem el principi.
while(list($a, $b) = each($resultwhile))
{
//echo "_________ $a ==>________ $b\n"; $b=id_lac
$sql = " SELECT h.herd_id, h.codi, p.milk,p.scc
FROM production p, herd h
WHERE h.codi = '$codivaca'
and p.fk_milklac_id = '$b'
AND h.herd_id = p.herd_id
GROUP BY p.testdate
";
//echo $sql;
$consultsql=new Consultabd($localhost,$userbd,'',$_SESSION['bd']);
$result=$consultsql->executar($sql);
while($row=mysql_fetch_array($result)) // Extreu la fila resultant com una matriu associativa (clau,valor)
{
if ($i==0)
$ydata1[]= $row["milk"];
if ($i==1)
$ydatab[]= $row["milk"];
if ($i==2)
$ydatac[]= $row["milk"];
if ($i==3)
$ydatad[]= $row["milk"];
if ($i==4)
$ydatae[]= $row["milk"];
if ($i==5)
$ydataf[]= $row["milk"];
}
$i=$i+1;
}
// Quan ja tenim les dades guardades per crear el gràfic, creem un nou gràfic de 300x200
$graphllet = new Graph(300, 200, "auto"); //mides del grafic
$graphllet->SetScale( "textlin");
$graphllet->img->SetMargin(35,55,35,40); //(margeesquerra,margedret,margesuperior,margeinferior
//titols
$graphllet->title->Set( $titol1. " Num: ".$codivaca. " Any ". $anydades);
$graphllet->xaxis->title->Set('Mesos');
$graphllet->yaxis->title->Set($titol1); //eixy
// Get localised version of the month names
$graphllet->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
if(isset ($ydata1))
{
$lineplot1 = new lineplot($ydata1);
$lineplot1->SetColor("blue"); //tipus grafic és la variable que guarda lineplot o barplot.
$lineplot1->SetLegend('ydata1');
$graphllet->Add($lineplot1);
}
if(isset ($ydatab))
{
$lineplot2 = new lineplot($ydatab);
$lineplot2->SetColor("red"); //tipus grafic és la variable que guarda lineplot o barplot.
$lineplot2->SetLegend('ydatab');
$graphllet->Add($lineplot2);
}
if(isset ($ydatac))
{
$lineplot3 = new lineplot($ydatac);
$lineplot3->SetColor("black"); //tipus grafic és la variable que guarda lineplot o barplot.
$lineplot3->SetLegend('ydatac');
$graphllet->Add($lineplot3);
}
if(isset ($ydatad))
{
$lineplot4 = new lineplot($ydatad);
$lineplot4->SetColor("green"); //tipus grafic és la variable que guarda lineplot o barplot.
$lineplot4->SetLegend('ydatad');
$graphllet->Add($lineplot4);
}
// Augmentemm el marge del grafic per posar la llegenda
$graphllet->title->SetMargin(3);
$graphllet->title->SetFont(FF_COMIC,FS_NORMAL,12);
// llegenda
// Adjust the position of the legend box
$graphllet->legend->Pos(0.03,0.10);
$graphllet->Stroke("graficllet.png");[/LEFT]