par
Jeqla » 07 sept. 2006, 11:39
Bon, on va dire que mon problème est résolu car je sais de ou çà coince mais je ne sais toujours pas pourquoi... Voici le code que j'utilise pour créér ces camemberts. 9à bidouille de dedans mais de où ? Quelle est la fonction qui pourrait donner une erreur et faire l'effet d'un die() ?
/* Renseignements transmis avant l'execution de ce code :
* $ChartData : tableau des données à afficher
* $ChartDiameter : diametre du camembert
* $graph_coord : pour enregistrer le camembert
* $typederesul : pour enregistrer le camembert
*/
//Paramètres du graphique
$ChartFont = 5;
$ChartFontHeight = imagefontheight($ChartFont);
//Calcul de la taille du graphique
$ChartWidth = $ChartDiameter + 20;
$ChartHeight = $ChartDiameter + 20 +
(($ChartFontHeight + 2) * count($ChartData));
//Calcul du total de toutes les valeurs
$ChartTotal = array_sum($ChartData);
//Calcul du centre du camembert
$ChartCenterX = $ChartDiameter/2 + 10;
$ChartCenterY = $ChartDiameter/2 + 10;
//Création de l'image
$image = imagecreate($ChartWidth, $ChartHeight);
//imageantialias($image, TRUE);
//Création d'un pinceau arrondi pour le tracé des bordures
$dot = imagecreate(3,3);
$dotColorBlack = imagecolorallocate($dot, 0, 0, 0);
$dotColorTransparent = imagecolorallocate($dot, 255, 0, 255);
imagecolortransparent($dot, $dotColorTransparent);
imagefill($dot, 0, 0, $dotColorTransparent);
imagefilledellipse($dot, 4, 4, 5, 5, $dotColorBlack);
imagesetbrush($image, $dot);
//Allocation des couleurs
$colorBody = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorBorder = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorText = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorSlice = array(
imagecolorallocate($image, 0x28, 0xD8, 0xA6),
imagecolorallocate($image, 0x8B, 0xD6, 0xDF),
imagecolorallocate($image, 0x79, 0x7A, 0xAC),
imagecolorallocate($image, 0xFF, 0xFF, 0x00),
imagecolorallocate($image, 0xFF, 0x00, 0xFF),
imagecolorallocate($image, 0x00, 0xFF, 0xFF),
imagecolorallocate($image, 0x99, 0x00, 0x00),
imagecolorallocate($image, 0x00, 0x99, 0x00),
imagecolorallocate($image, 0x00, 0x00, 0x99),
imagecolorallocate($image, 0x99, 0x99, 0x00),
imagecolorallocate($image, 0x99, 0x00, 0x99),
imagecolorallocate($image, 0x00, 0x99, 0x99));
//Remplissage de l'arrière-plan
imagefill($image, 0, 0, $colorBody);
//Tracé de chaque tranche
$Degrees = 90;
$slice=0;
foreach($ChartData as $label=>$value)
{
$StartDegrees = round($Degrees);
$Degrees += (($value/$ChartTotal)*360);
$EndDegrees = round($Degrees);
$CurrentColor = $colorSlice[$slice%(count($colorSlice))];
//Tracé des tranches du camembert
imagefilledarc(
$image,
$ChartCenterX, $ChartCenterY,
$ChartDiameter,$ChartDiameter,
$StartDegrees, $EndDegrees,
$CurrentColor, IMG_ARC_PIE);
//Tracé de la légende de cette tranche
$LineY = $ChartDiameter + 20 +
($slice*($ChartFontHeight+2));
imagerectangle($image,
10,
$LineY,
10 + $ChartFontHeight,
$LineY+$ChartFontHeight,
$colorBorder);
imagefilltoborder($image,
12,
$LineY + 2,
$colorBorder,
$CurrentColor);
imagestring($image,
$ChartFont,
20 + $ChartFontHeight,
$LineY,
"$label: $value",
$colorText);
$slice++;
}
//Tracé de la bordure
imageellipse($image,
$ChartCenterX, $ChartCenterY,
$ChartDiameter,$ChartDiameter,
IMG_COLOR_BRUSHED);
//Envoi de l'image
$nomduchemin="../graph/".$graph_coord.$typederesul.".png";
imagepng($image,$nomduchemin);
imagedestroy($image);
Bon, on va dire que mon problème est résolu car je sais de ou çà coince mais je ne sais toujours pas pourquoi... Voici le code que j'utilise pour créér ces camemberts. 9à bidouille de dedans mais de où ? Quelle est la fonction qui pourrait donner une erreur et faire l'effet d'un die() ?
[php]/* Renseignements transmis avant l'execution de ce code :
* $ChartData : tableau des données à afficher
* $ChartDiameter : diametre du camembert
* $graph_coord : pour enregistrer le camembert
* $typederesul : pour enregistrer le camembert
*/
//Paramètres du graphique
$ChartFont = 5;
$ChartFontHeight = imagefontheight($ChartFont);
//Calcul de la taille du graphique
$ChartWidth = $ChartDiameter + 20;
$ChartHeight = $ChartDiameter + 20 +
(($ChartFontHeight + 2) * count($ChartData));
//Calcul du total de toutes les valeurs
$ChartTotal = array_sum($ChartData);
//Calcul du centre du camembert
$ChartCenterX = $ChartDiameter/2 + 10;
$ChartCenterY = $ChartDiameter/2 + 10;
//Création de l'image
$image = imagecreate($ChartWidth, $ChartHeight);
//imageantialias($image, TRUE);
//Création d'un pinceau arrondi pour le tracé des bordures
$dot = imagecreate(3,3);
$dotColorBlack = imagecolorallocate($dot, 0, 0, 0);
$dotColorTransparent = imagecolorallocate($dot, 255, 0, 255);
imagecolortransparent($dot, $dotColorTransparent);
imagefill($dot, 0, 0, $dotColorTransparent);
imagefilledellipse($dot, 4, 4, 5, 5, $dotColorBlack);
imagesetbrush($image, $dot);
//Allocation des couleurs
$colorBody = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorBorder = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorText = imagecolorallocate($image, 0x00, 0x00, 0x00);
$colorSlice = array(
imagecolorallocate($image, 0x28, 0xD8, 0xA6),
imagecolorallocate($image, 0x8B, 0xD6, 0xDF),
imagecolorallocate($image, 0x79, 0x7A, 0xAC),
imagecolorallocate($image, 0xFF, 0xFF, 0x00),
imagecolorallocate($image, 0xFF, 0x00, 0xFF),
imagecolorallocate($image, 0x00, 0xFF, 0xFF),
imagecolorallocate($image, 0x99, 0x00, 0x00),
imagecolorallocate($image, 0x00, 0x99, 0x00),
imagecolorallocate($image, 0x00, 0x00, 0x99),
imagecolorallocate($image, 0x99, 0x99, 0x00),
imagecolorallocate($image, 0x99, 0x00, 0x99),
imagecolorallocate($image, 0x00, 0x99, 0x99));
//Remplissage de l'arrière-plan
imagefill($image, 0, 0, $colorBody);
//Tracé de chaque tranche
$Degrees = 90;
$slice=0;
foreach($ChartData as $label=>$value)
{
$StartDegrees = round($Degrees);
$Degrees += (($value/$ChartTotal)*360);
$EndDegrees = round($Degrees);
$CurrentColor = $colorSlice[$slice%(count($colorSlice))];
//Tracé des tranches du camembert
imagefilledarc(
$image,
$ChartCenterX, $ChartCenterY,
$ChartDiameter,$ChartDiameter,
$StartDegrees, $EndDegrees,
$CurrentColor, IMG_ARC_PIE);
//Tracé de la légende de cette tranche
$LineY = $ChartDiameter + 20 +
($slice*($ChartFontHeight+2));
imagerectangle($image,
10,
$LineY,
10 + $ChartFontHeight,
$LineY+$ChartFontHeight,
$colorBorder);
imagefilltoborder($image,
12,
$LineY + 2,
$colorBorder,
$CurrentColor);
imagestring($image,
$ChartFont,
20 + $ChartFontHeight,
$LineY,
"$label: $value",
$colorText);
$slice++;
}
//Tracé de la bordure
imageellipse($image,
$ChartCenterX, $ChartCenterY,
$ChartDiameter,$ChartDiameter,
IMG_COLOR_BRUSHED);
//Envoi de l'image
$nomduchemin="../graph/".$graph_coord.$typederesul.".png";
imagepng($image,$nomduchemin);
imagedestroy($image);[/php]