par
Elie » 12 juin 2014, 21:14
Le problème vient alors de ta requete SQL car avec mon code simplifié ca marche :
<?php
$moisFr=array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Decembre');
$resultat=array(2 => 24, 6 => 32, 7 => 60);
$i=3;
$min = 24;
$max = 60;
header('Content-type: image/png');
$font_file = './arial.ttf';
$largeur=$i*50+90;
$hauteur=400;
$absis=80;
$courbe = imagecreatetruecolor($largeur, $hauteur);
$bleu=imagecolorallocate($courbe, 0, 0, 255);
$ligne=imagecolorallocate($courbe, 220, 220, 220);
$fond=imagecolorallocate($courbe, 250, 250, 250);
$noir=imagecolorallocate($courbe, 0, 0, 0);
$rouge=imagecolorallocate($courbe, 255, 0, 0);
imagefilledrectangle($courbe,0 , 0, $largeur, $hauteur, $fond);
imageline($courbe, 50, $hauteur-$absis, $largeur-10,$hauteur-$absis, $noir);
imageline($courbe, 50,$hauteur-$absis,50,20, $noir);
if($min!=0)
{
$absis+=10;
$a=10;
}
$nbOrdonne=10;
$echelleX=($largeur-100)/$i;
$echelleY=($hauteur-$absis-20)/$nbOrdonne;
$i=$min;
$py=($max-$min)/$nbOrdonne;
$pasY=$absis;
while($pasY<($hauteur-19))
{
imagestring($courbe, 2,10 , $hauteur-$pasY-6, round($i), $noir);
imageline($courbe, 50, $hauteur-$pasY, $largeur-20,$hauteur-$pasY, $ligne);
$pasY+=$echelleY;
$i+=$py;
}
$j=-1;
$pasX=90;
foreach ($resultat as $mois => $numero) {
$y=($hauteur) -(($numero -$min) * ($echelleY/$py))-$absis;
imagefilledellipse($courbe, $pasX, $y, 6, 6, $rouge);
//imagefttext($courbe, 10, 315, $pasX, $hauteur-$absis+20, $noir, 1, $moisFr[$mois-1]);
imagestring($courbe, 2, $pasX , $hauteur-$absis+20, $moisFr[$mois-1], $noir);
imageline($courbe, $pasX, $hauteur-$absis+$a, $pasX,$y, $noir);
if($j!==-1)
{
imageline($courbe,($pasX-$echelleX),$yprev,$pasX,$y,$noir);
}
imagestring($courbe, 2, $pasX-15,$y-14 , $numero, $bleu);
$j=$numero;
$yprev=$y;
$pasX+=$echelleX;
}
imagepng($courbe);
imagedestroy($courbe);
?>
Le problème vient alors de ta requete SQL car avec mon code simplifié ca marche :
[php]<?php
$moisFr=array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Decembre');
$resultat=array(2 => 24, 6 => 32, 7 => 60);
$i=3;
$min = 24;
$max = 60;
header('Content-type: image/png');
$font_file = './arial.ttf';
$largeur=$i*50+90;
$hauteur=400;
$absis=80;
$courbe = imagecreatetruecolor($largeur, $hauteur);
$bleu=imagecolorallocate($courbe, 0, 0, 255);
$ligne=imagecolorallocate($courbe, 220, 220, 220);
$fond=imagecolorallocate($courbe, 250, 250, 250);
$noir=imagecolorallocate($courbe, 0, 0, 0);
$rouge=imagecolorallocate($courbe, 255, 0, 0);
imagefilledrectangle($courbe,0 , 0, $largeur, $hauteur, $fond);
imageline($courbe, 50, $hauteur-$absis, $largeur-10,$hauteur-$absis, $noir);
imageline($courbe, 50,$hauteur-$absis,50,20, $noir);
if($min!=0)
{
$absis+=10;
$a=10;
}
$nbOrdonne=10;
$echelleX=($largeur-100)/$i;
$echelleY=($hauteur-$absis-20)/$nbOrdonne;
$i=$min;
$py=($max-$min)/$nbOrdonne;
$pasY=$absis;
while($pasY<($hauteur-19))
{
imagestring($courbe, 2,10 , $hauteur-$pasY-6, round($i), $noir);
imageline($courbe, 50, $hauteur-$pasY, $largeur-20,$hauteur-$pasY, $ligne);
$pasY+=$echelleY;
$i+=$py;
}
$j=-1;
$pasX=90;
foreach ($resultat as $mois => $numero) {
$y=($hauteur) -(($numero -$min) * ($echelleY/$py))-$absis;
imagefilledellipse($courbe, $pasX, $y, 6, 6, $rouge);
//imagefttext($courbe, 10, 315, $pasX, $hauteur-$absis+20, $noir, 1, $moisFr[$mois-1]);
imagestring($courbe, 2, $pasX , $hauteur-$absis+20, $moisFr[$mois-1], $noir);
imageline($courbe, $pasX, $hauteur-$absis+$a, $pasX,$y, $noir);
if($j!==-1)
{
imageline($courbe,($pasX-$echelleX),$yprev,$pasX,$y,$noir);
}
imagestring($courbe, 2, $pasX-15,$y-14 , $numero, $bleu);
$j=$numero;
$yprev=$y;
$pasX+=$echelleX;
}
imagepng($courbe);
imagedestroy($courbe);
?>[/php]