I have written the php code to generate a pie chart from the data in MySQL, however the whole pie chart turns into yello colour rather than showing the information in different colors. What can I do to make it works?Thank you very much. I have created two files, one is testingpiechart.php and testingpie.php

Here's my code:

<?php
$slide = $one + $two + $third + $fourth + $fifth; 
// + $sixth;
header('Content-type: image/png');
$handle = imagecreate(100, 100);
$background = imagecolorallocate($handle, 255, 255, 255);
$red = imagecolorallocate($handle, 255, 0, 0);
$green = imagecolorallocate($handle, 0, 255, 0);
$blue = imagecolorallocate($handle, 0, 0, 255);
$purple = imagecolorallocate($handle, 186, 85, 211);
$pink = imagecolorallocate($handle, 255, 181, 197);
$yellow = imagecolorallocate($handle, 255, 255, 0);
$black = imagecolorallocate($handle, 0, 0, 0);
$white = imagecolorallocate($handle, 255, 255, 255);
$grey = imagecolorallocate($handle, 100, 100, 100);

$darkred = imagecolorallocate($handle, 150, 0, 0);
$darkgreen = imagecolorallocate($handle, 0, 150, 0);
$darkblue = imagecolorallocate($handle, 0, 0, 150);
$darkpurple = imagecolorallocate($handle, 148, 0, 211);
$darkpink = imagecolorallocate($handle, 255, 20, 147);
$darkyellow = imagecolorallocate($handle, 205, 205, 0);


// 3D look
for ($i = 60; $i > 50; $i--)
{
imagefilledarc($handle, 50, $i, 100, 50, 0, $one, $darkred, IMG_ARC_PIE);
//imagefilledarc($handle, 50, $i, 100, 50, $one, $two , $darkblue, IMG_ARC_PIE);
//imagefilledarc($handle, 50, $i, 100, 50, $two, $third , $darkgreen, IMG_ARC_PIE);
//imagefilledarc($handle, 50, $i, 100, 50, $third, $fourth, $darkpurple, IMG_ARC_PIE);
//imagefilledarc($handle, 50, $i, 100, 50, $fourth, $fifth , $darkpink, IMG_ARC_PIE);
//imagefilledarc($handle, 50, $i, 100, 50, $sixth, 360 , $darkyellow, IMG_ARC_PIE);

imagefilledarc($handle, 50, $i, 100, 50, $one, $slide , $darkblue, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide , $darkgreen, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide, $darkpurple, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide , $darkpink, IMG_ARC_PIE);
imagefilledarc($handle, 50, $i, 100, 50, $slide, 360 , $darkyellow, IMG_ARC_PIE);
}

imagefilledarc($handle, 50, 50, 100, 50, 0, $one , $red, IMG_ARC_PIE);
//imagefilledarc($handle, 50, 50, 100, 50, $one, $two , $blue, IMG_ARC_PIE);
//imagefilledarc($handle, 50, 50, 100, 50, $two, $third , $green, IMG_ARC_PIE);
//imagefilledarc($handle, 50, 50, 100, 50, $third, $fourth , $purple, IMG_ARC_PIE);
//imagefilledarc($handle, 50, 50, 100, 50, $fourth, $fifth , $pink, IMG_ARC_PIE);
//imagefilledarc($handle, 50, 50, 100, 50, $fifth, 360 , $yellow, IMG_ARC_PIE);

imagefilledarc($handle, 50, 50, 100, 50, $one, $slide , $blue, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $green, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $purple, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $pink, IMG_ARC_PIE);
imagefilledarc($handle, 50, 50, 100, 50, $slide, 360 , $yellow, IMG_ARC_PIE);

imagepng($handle);

?>

testingpie.php

<?
// Connects to your Database 
mysql_connect("localhost", "", "") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error()); 
 
$getnumofvote = mysql_query("select Number_of_Vote from Candidate");
$sum = mysql_query("SELECT SUM(Number_of_Vote) FROM Candidate");
$total = mysql_result($sum,0,0);

//first row and first column
$getvote1 = mysql_result($getnumofvote,0,0);
$getvote2 = mysql_result($getnumofvote,1,0);
$getvote3 = mysql_result($getnumofvote,2,0);
$getvote4 = mysql_result($getnumofvote,3,0);
$getvote5 = mysql_result($getnumofvote,4,0);
$getvote6 = mysql_result($getnumofvote,5,0);

$one = round (360 * $getvote1 / $total); 
$two = round (360 * $getvote2 / $total); 
$third = round (360 * $getvote3 / $total); 
$fourth = round (360 * $getvote4 / $total); 
$fifth = round (360 * $getvote5 / $total); 
//$sixth = round (360 * $getvote6 / $total); 



$per1 = round ($getvote1 / $total * 100); 
$per2 = round ($getvote2 / $total * 100); 
$per3 = round ($getvote3 / $total * 100); 
$per4 = round ($getvote4 / $total * 100); 
$per5 = round ($getvote5 / $total * 100); 
$per6 = round ($getvote6 / $total * 100); 


echo "<img src=testingpiechart.php?one=".$one."&two=".$two."&third=".$third."&fourth=".$fourth."&fifth=".$fifth."><br>"; 
echo "<font color=ff0000>ee</font> = $getvote1 Vote(s), $per1 %<br>
<font color=0000ff>SECOND </font> = $getvote2 Vote(s), $per2 %<br> 
<font color=00ff00>THIRD </font> = $getvote3 Vote(s), $per3 %<br>
<font color=ba55d3>FOURTH </font> = $getvote4 Vote(s), $per4 %<br>
<font color=ffb5c5>Fifth </font> = $getvote5 Vote(s), $per5 %<br>
<font color=ffff00>Sixth </font> = $getvote6 Vote(s), $per6 %<br>
"; 

?>
This article has been dead for over six months. Start a new discussion instead.