473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with Pie Chart

3 New Member
Hello I have created this php file in order to create a pie chart, 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. I have created 2 files, one is testingpiechart.php and the other one is testingpie.php.
Here's my code:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. <?php
  5. $slide = $one + $two + $third + $fourth + $fifth; 
  6. // + $sixth;
  7. header('Content-type: image/png');
  8. $handle = imagecreate(100, 100);
  9. $background = imagecolorallocate($handle, 255, 255, 255);
  10. $red = imagecolorallocate($handle, 255, 0, 0);
  11. $green = imagecolorallocate($handle, 0, 255, 0);
  12. $blue = imagecolorallocate($handle, 0, 0, 255);
  13. $purple = imagecolorallocate($handle, 186, 85, 211);
  14. $pink = imagecolorallocate($handle, 255, 181, 197);
  15. $yellow = imagecolorallocate($handle, 255, 255, 0);
  16. $black = imagecolorallocate($handle, 0, 0, 0);
  17. $white = imagecolorallocate($handle, 255, 255, 255);
  18. $grey = imagecolorallocate($handle, 100, 100, 100);
  19.  
  20. $darkred = imagecolorallocate($handle, 150, 0, 0);
  21. $darkgreen = imagecolorallocate($handle, 0, 150, 0);
  22. $darkblue = imagecolorallocate($handle, 0, 0, 150);
  23. $darkpurple = imagecolorallocate($handle, 148, 0, 211);
  24. $darkpink = imagecolorallocate($handle, 255, 20, 147);
  25. $darkyellow = imagecolorallocate($handle, 205, 205, 0);
  26.  
  27.  
  28. // 3D look
  29. for ($i = 60; $i > 50; $i--)
  30. {
  31. imagefilledarc($handle, 50, $i, 100, 50, 0, $one, $darkred, IMG_ARC_PIE);
  32. //imagefilledarc($handle, 50, $i, 100, 50, $one, $two , $darkblue, IMG_ARC_PIE);
  33. //imagefilledarc($handle, 50, $i, 100, 50, $two, $third , $darkgreen, IMG_ARC_PIE);
  34. //imagefilledarc($handle, 50, $i, 100, 50, $third, $fourth, $darkpurple, IMG_ARC_PIE);
  35. //imagefilledarc($handle, 50, $i, 100, 50, $fourth, $fifth , $darkpink, IMG_ARC_PIE);
  36. //imagefilledarc($handle, 50, $i, 100, 50, $sixth, 360 , $darkyellow, IMG_ARC_PIE);
  37.  
  38. imagefilledarc($handle, 50, $i, 100, 50, $one, $slide , $darkblue, IMG_ARC_PIE);
  39. imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide , $darkgreen, IMG_ARC_PIE);
  40. imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide, $darkpurple, IMG_ARC_PIE);
  41. imagefilledarc($handle, 50, $i, 100, 50, $slide, $slide , $darkpink, IMG_ARC_PIE);
  42. imagefilledarc($handle, 50, $i, 100, 50, $slide, 360 , $darkyellow, IMG_ARC_PIE);
  43. }
  44.  
  45. imagefilledarc($handle, 50, 50, 100, 50, 0, $one , $red, IMG_ARC_PIE);
  46. //imagefilledarc($handle, 50, 50, 100, 50, $one, $two , $blue, IMG_ARC_PIE);
  47. //imagefilledarc($handle, 50, 50, 100, 50, $two, $third , $green, IMG_ARC_PIE);
  48. //imagefilledarc($handle, 50, 50, 100, 50, $third, $fourth , $purple, IMG_ARC_PIE);
  49. //imagefilledarc($handle, 50, 50, 100, 50, $fourth, $fifth , $pink, IMG_ARC_PIE);
  50. //imagefilledarc($handle, 50, 50, 100, 50, $fifth, 360 , $yellow, IMG_ARC_PIE);
  51.  
  52. imagefilledarc($handle, 50, 50, 100, 50, $one, $slide , $blue, IMG_ARC_PIE);
  53. imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $green, IMG_ARC_PIE);
  54. imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $purple, IMG_ARC_PIE);
  55. imagefilledarc($handle, 50, 50, 100, 50, $slide, $slide , $pink, IMG_ARC_PIE);
  56. imagefilledarc($handle, 50, 50, 100, 50, $slide, 360 , $yellow, IMG_ARC_PIE);
  57.  
  58. imagepng($handle);
  59.  
  60. ?>
  61.  
testingpie.php
Expand|Select|Wrap|Line Numbers
  1. <?
  2. // Connects to your Database 
  3. mysql_connect("localhost", "", "") or die(mysql_error()); 
  4. mysql_select_db("db") or die(mysql_error()); 
  5.  
  6. $getnumofvote = mysql_query("select Number_of_Vote from Candidate");
  7. $sum = mysql_query("SELECT SUM(Number_of_Vote) FROM Candidate");
  8. $total = mysql_result($sum,0,0);
  9.  
  10. //first row and first column
  11. $getvote1 = mysql_result($getnumofvote,0,0);
  12. $getvote2 = mysql_result($getnumofvote,1,0);
  13. $getvote3 = mysql_result($getnumofvote,2,0);
  14. $getvote4 = mysql_result($getnumofvote,3,0);
  15. $getvote5 = mysql_result($getnumofvote,4,0);
  16. $getvote6 = mysql_result($getnumofvote,5,0);
  17.  
  18. $one = round (360 * $getvote1 / $total); 
  19. $two = round (360 * $getvote2 / $total); 
  20. $third = round (360 * $getvote3 / $total); 
  21. $fourth = round (360 * $getvote4 / $total); 
  22. $fifth = round (360 * $getvote5 / $total); 
  23. //$sixth = round (360 * $getvote6 / $total); 
  24.  
  25.  
  26.  
  27. $per1 = round ($getvote1 / $total * 100); 
  28. $per2 = round ($getvote2 / $total * 100); 
  29. $per3 = round ($getvote3 / $total * 100); 
  30. $per4 = round ($getvote4 / $total * 100); 
  31. $per5 = round ($getvote5 / $total * 100); 
  32. $per6 = round ($getvote6 / $total * 100); 
  33.  
  34.  
  35. echo "<img src=testingpiechart.php?one=".$one."&two=".$two."&third=".$third."&fourth=".$fourth."&fifth=".$fifth."><br>"; 
  36. echo "<font color=ff0000>ee</font> = $getvote1 Vote(s), $per1 %<br>
  37. <font color=0000ff>SECOND </font> = $getvote2 Vote(s), $per2 %<br> 
  38. <font color=00ff00>THIRD </font> = $getvote3 Vote(s), $per3 %<br>
  39. <font color=ba55d3>FOURTH </font> = $getvote4 Vote(s), $per4 %<br>
  40. <font color=ffb5c5>Fifth </font> = $getvote5 Vote(s), $per5 %<br>
  41. <font color=ffff00>Sixth </font> = $getvote6 Vote(s), $per6 %<br>
  42. "; 
  43.  
  44. ?><?
  45. // Connects to your Database 
  46. mysql_connect("localhost", "", "") or die(mysql_error()); 
  47. mysql_select_db("db") or die(mysql_error()); 
  48.  
  49. $getnumofvote = mysql_query("select Number_of_Vote from Candidate");
  50. $sum = mysql_query("SELECT SUM(Number_of_Vote) FROM Candidate");
  51. $total = mysql_result($sum,0,0);
  52.  
  53. //first row and first column
  54. $getvote1 = mysql_result($getnumofvote,0,0);
  55. $getvote2 = mysql_result($getnumofvote,1,0);
  56. $getvote3 = mysql_result($getnumofvote,2,0);
  57. $getvote4 = mysql_result($getnumofvote,3,0);
  58. $getvote5 = mysql_result($getnumofvote,4,0);
  59. $getvote6 = mysql_result($getnumofvote,5,0);
  60.  
  61. $one = round (360 * $getvote1 / $total); 
  62. $two = round (360 * $getvote2 / $total); 
  63. $third = round (360 * $getvote3 / $total); 
  64. $fourth = round (360 * $getvote4 / $total); 
  65. $fifth = round (360 * $getvote5 / $total); 
  66. //$sixth = round (360 * $getvote6 / $total); 
  67.  
  68. echo "<img src=testingpiechart.php?one=".$one."&two=".$two."&third=".$third."&fourth=".$fourth."&fifth=".$fifth."><br>"; 
  69. echo "<font color=ff0000>ee</font> = $getvote1 Vote(s<br>
  70. <font color=0000ff>SECOND </font> = $getvote2 Vote(s)<br> 
  71. <font color=00ff00>THIRD </font> = $getvote3 Vote(s)<br>
  72. <font color=ba55d3>FOURTH </font> = $getvote4 Vote(s)<br>
  73. <font color=ffb5c5>Fifth </font> = $getvote5 Vote(s)<br>
  74. <font color=ffff00>Sixth </font> = $getvote6 Vote(s)<br>
  75. "; 
  76.  
  77. ?>
  78.  
  79.  
Mar 4 '08 #1
4 1641
hsriat
1,654 Recognized Expert Top Contributor
Line 2:[php]$slide = $_GET['one'] + $_GET['two'] + $_GET['third'] + $_GET['fourth'] + $_GET['fifth'];[/php]
Mar 4 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
Also, rather then sending data as one, two, third etc, try to send it as a string separated by comas. On the other end, exploded() it into array to get the parameters. With that you can have more than 5 parameters.
Mar 4 '08 #3
euniceee
3 New Member
Line 2:[php]$slide = $_GET['one'] + $_GET['two'] + $_GET['third'] + $_GET['fourth'] + $_GET['fifth'];[/php]
it's getting better now, it's showing 2 slides out of 6. What else can I change to make it display the whole pie chart?Thank you.
Mar 4 '08 #4
hsriat
1,654 Recognized Expert Top Contributor
it's getting better now, it's showing 2 slides out of 6. What else can I change to make it display the whole pie chart?Thank you.
Add[php]$one = $_GET[one];
$two = $_GET[two];
$third = $_GET[third];
$fourth = $_GET[fourth];
$fifth = $_GET[fifth];[/php] in the starting of testingpiechart.php.

Also the arguments you have used for the function imagefilledarc in testingpiechart.php will not give you the result you want. Modify the $start and $end accordingly.
Mar 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Prabhakar | last post by:
Friends, I have been migrating ASP applications from IIS4.0/NT4.0 to IIS5.0/W2K. All the applications working perfectly except one. This particular application will make use of asp chart object....
0
by: Michael Fork | last post by:
Note: I pasted the code the attachments as plain text after the message (I wasn't able to post it with an attachment...) Attached are the XSL and XML files that I am having problems with. I am...
1
by: Eric | last post by:
I am trying to figure out a good way to implement a XSLT transformation. Basically my goal is that I want to be able to ouput the following XML in a document: <chart type="pie" width="100"...
1
by: Jim | last post by:
I have this chart on a form. I'm trying to get this chart to render only if the user chooses to do so. This because of that the chart is quite complex and takes some time to render. I know that I...
2
by: borekfm | last post by:
Hitting two problems when running a new report I've created, that contains a chart/graph. The chart shows three series, two are shown as lines and one as an area. The data come from three different...
22
by: PeteCresswell | last post by:
I've been to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mschrt/html/vbobjtitleobject.asp, but still don't have a clue. For example, I've got a chart object namde...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
0
by: gazelle04 | last post by:
I have a report with pie chart. I formatted the chart with what my own formats like putting the legent at the bottom, changing the size of fonts, etc. When I use that same report format into another...
0
by: Wayne | last post by:
I am charting data from a query that consists of a Date/Time field and a Number field. The Date/Time field is the x scale on my chart. Sometimes data is collected from different times during the...
1
by: cubekid | last post by:
I am using OWC 11 in my new web application for displaying charts. Is it possible in OWC 11 to combine and display a column and a line graph (Looking like they overlap each other)? I tried it using...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.