making pie charts and bar charts?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

making pie charts and bar charts?

Post by rami »

i am doing surveys and all done now
not i count results and displaying results in percentage
i want to display results in barcharts and pie charts

how can i do that
any good ideas
i have seen poll scripts using series of small images to do that

aren't there any better idea?


next thing i want to print page in good format (if it is not good in web browser) ok as pdf

how can i do that?
any better ideas

thanks
rami
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

You can do it with GD, there are some examples in the online manual under (imagefilledellipse, imagefilledarc, imagefill and imagefilledpolygon). Also if you download the manual, you will find other examples that may have been removed from the online manual.

pif!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

JPGraph.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

As to your pdf needs - I'd recommend fpdf.

aerodromoi
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

Post by rami »

printf wrote:You can do it with GD, there are some examples in the online manual under (imagefilledellipse, imagefilledarc, imagefill and imagefilledpolygon). Also if you download the manual, you will find other examples that may have been removed from the online manual.

pif!
well i have a survey file which shows result as follows

Code: Select all

<?
session_start();
$cb2 = $_GET['cb2'];
$one=0;
$two=0;
$three=0;
$four=0;
$five=0;
$gtotal=0;
$obtain=0;
$full=0;
$percent=0;
$zero=0;
$grandobtain=0;
$array[1]='what is your name'; 
$array[2]='your add';
$array[3]='question no 3 will go here';
$array[4]='question no 4 will go here';
$array[5]='question no 5 will go here';
$array[6]='question no 6 will go here';
$array[7]='question no 7 will go here';
$array[8]='question no 8 will go here';
$array[9]='question no 9 will go here';
$array[10]='question no 10 will go here';
$array[11]='question no 11 will go here';
$array[12]='question no 12 will go here';

if ($cb2==20021 OR $cb2==20022)
{
$sem=7;
}	
elseif ($cb2==20031 OR $cb2==20032)
{
$sem=5;
}	
elseif ($cb2==20041 OR $cb2==20042)
{
$sem=3;
}			
elseif ($cb2==20051 OR $cb2==20052 OR $cb2=20053)
{
$sem=1;
}	
require_once ('../mysql_connect1.php'); 
if (!isset($_SESSION['suser_id']))
{

	header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "index.php");
	ob_end_clean(); // Delete the buffer.
	exit(); // Quit the script.
	
} else { 
$page_title = 'view';
include_once ('head.htm'); 
if (isset($_GET['uid'])) {

$query1 = "SELECT distinct(subject) FROM survey WHERE (teach_id =". $_GET['uid']." AND batch_id=$cb2 AND semester=$sem)";
echo '<table border="1" width="90%" cellspacing="3" cellpadding="3" align="center">';
$result1 = mysql_query ($query1);
while ($row = mysql_fetch_array ($result1, MYSQL_ASSOC)) 
{	
	echo "	<tr><td align="center" width="25%" bgcolor="00659C"><b><font color=white>Subject</font></b></td>
<td align="center"  bgcolor="00659C">
<b><font color=white>{$row['subject']}</font></b></td>	</tr>\n";	
} 





$query = "SELECT teach_id FROM survey WHERE (teach_id = {$_GET['uid']} AND batch_id=$cb2 AND semester=$sem)";		
		$result = @mysql_query ($query);
$total=mysql_num_rows($result);

echo '<table border="0" width="90%" cellspacing="3" cellpadding="2" align="center" bgcolor="#EFEFEF">
<tr>
</tr>';
$full=$total*5;
echo "	<tr>
		<td align="center" bgcolor="blue" ><b><font color=white>Total Number of Respondents</font></b></td>
		<td align="center" bgcolor="blue"><font color=white>$total</font></td>
		<td align="center" bgcolor="blue"></td>
	</tr>\n";
	echo "	<tr>
	<td align="center" width="50%" bgcolor="00659C"><b><font color=white>Number of</font></b></td>
<td align="center" width="20%" bgcolor="00659C"><b><font color=white>Total</font></b></td>
<td align="center" width="20%" bgcolor="00659C"><b><font color=white>In percent</font></b></td>
</tr>\n";
for ($j = 1; $j <= 12; $j++) 
{
$obtain=0;
$percent=0;
echo "	<tr>
		<td align="center" bgcolor="red" ><b>Result for question No</b></td>
		<td align="center" bgcolor="red">$j</td>
		<td align="center" bgcolor="red"></td>
	</tr>\n";
	echo "	<tr>
		<td bgcolor="red" width="60%">$array[$j]</b></td>
	</tr>\n";

for ($i = 0; $i <= 5; $i++) {
$res = mysql_result(mysql_query("SELECT COUNT(user_id) FROM survey where batch_id=$cb2 AND teach_id = {$_GET['uid']} AND semester=$sem AND q$j=$i"),0);
	$per=($res/$total)*100;
	$obtain=$obtain+($res*$i);

echo "	<tr>
		<td align="center" ><b>$i</b></td>
		<td align="center">$res</td>
		<td align="center">$per</td>
	</tr>\n";
		
//echo " number of $i is  $res</br>";
//echo " In Percent $per percent</br></br>";
		
if ($i==0)
{
$zero=$zero+$res;
}	
elseif ($i==1)
{
$one=$one+$res;
}	
elseif ($i==2)
{
$two=$two+$res;
}	
elseif ($i==3)
{
$three=$three+$res;
}			
elseif ($i==4)
{
$four=$four+$res;
}	
elseif ($i==5)
{
$five=$five+$res;
}		


}//close of i for
$percent=($obtain/$full)*100;
$grandobtain=$grandobtain+$obtain;
echo "	<tr>
		<td align="center" ><b>$percent % students agreed on this</b></td>
		<td align="center">$obtain out of $full</td>
		<td align="center"></td>
	</tr>\n";
}	//close of j for
$gtotal=$total*12;
echo "	<tr>
		<td align="right" bgcolor="blue"><b><font color=white>Detail</font></b></td>
		<td align="left" bgcolor="blue"><b><font color=white>Analysis</font></b></td>
		<td align="center" bgcolor="blue"></td>
	</tr>\n";
	echo "	<tr>
		<td align="center" ><b>Total Number of zero</b></td>
		<td align="center">$zero</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
echo "	<tr>
		<td align="center" ><b>Total Number of one</b></td>
		<td align="center">$one</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
	echo "	<tr>
		<td align="center" ><b>Total Number of two</b></td>
		<td align="center">$two</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
	echo "	<tr>
		<td align="center" ><b>Total Number of Three</b></td>
		<td align="center">$three</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
	echo "	<tr>
		<td align="center" ><b>Total Number of four</b></td>
		<td align="center">$four</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
	echo "	<tr>
		<td align="center" ><b>Total Number of five</b></td>
		<td align="center">$five</td>
		<td align="center">out of $gtotal</td>
	</tr>\n";
	$grandfull=$total*5*12;
$grandpercent=($grandobtain/$grandfull)*100;
echo " <b><center><font color=blue></br> Result:Obtain $grandobtain out of $grandfull which is $grandpercent%</font> </center></b></br>";
if ($grandpercent>80)
{
echo " <b><center><font color=red>Result:Excellent Response For this Teacher(Obtained More than 80%)</font> </center></b></br>";
}	
elseif ($grandpercent>70 AND  $grandpercent<=80)
{
echo " <b><center><font color=blue>Result:Very good Rating For this Teacher ( Obtained Between 70-80 % )</font> </center></b></br>";
}	
elseif ($grandpercent>50 AND $grandpercent<=75)
{
echo " <b><center><font color=green>Result:Average Rating For this Teacher (Obtained 50-75 % )</font> </center></b> </br>";
}	
elseif ($grandpercent>25 AND $grandpercent<=50)
{
echo " <b><center><font color=black>Result:Not a very Good Rating (Obtained 25-50 %) </font> </center></b></br>";
}			
elseif ($grandpercent<=25)
{
echo " <b><center><font color=brown>Result:Very poor Rating  For this Teacher (Obtained less than 25%) </font> </center></b></br>";
}	
else
{
echo " Average Rating  (Distrbuted Rating by Different Students) </br>";
}
echo '</table>';
}		
}			
?>
<body bgcolor=skyblue>
</body>
i want to use ggraph to make bar pie chart how can i do that...frankly i must say that that application ggraph is good but with poor documenatation
please help
how to use ggraph in this file..
thanks
Post Reply