ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Pie charts
Posted by Summaira on May-28-2009 17:47
Attachments:
Hi !

I want to read some data from database and the give this data to
"$data=array(x,y,z); in file "sidelabelpie.php".

I have attached final file which is not displaying graph.

Any1 know why this is happening??

Regards,
--Summaira
sidelabelpie.php
<?php 
include("../bin/php/php5.2.9-1/phpchartdir.php");



$hostname="localhost"; 
$mysql_login="root"; 
$mysql_password=""; 
$database="rttanalyzer"; 
// connect to the database server 
if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){ 
  die("Can't connect to database server.");     
}else{ 

	echo "Database connection successfull<br>";

  // select a database 
    if (!(mysql_select_db("$database",$db))){ 
     die("Can't connect to database."); 
    } 
} 
/*

	$sql=mysql_query("select source_ip,protocol from statistics order by ID");
	
$tcp=0;
$udp=0;
$othr=0;
while($row=mysql_fetch_array($sql))
{
	$data =$row["protocol"];
	
	if($data==6)
		$tcp++;
	else if($data==17)
		$udp++;
	else
		$othr++;
	
	
	
}*/

$tcp=10;
$udp=3;
$others=0;
$data = array($tcp,$udp,$others);

# The labels for the pie chart
$labels = array("TCP", "UDP", "Others");

# Create a PieChart object of size 560 x 270 pixels, with a golden background and a 1
# pixel 3D border
$c = new PieChart(560, 270, goldColor(), -1, 1);

# Add a title box using 15 pts Times Bold Italic font and metallic pink background
# color
$textBoxObj = $c->addTitle("Traffic Statistics", "timesbi.ttf", 15);
$textBoxObj->setBackground(metalColor(0xff9999));

# Set the center of the pie at (280, 135) and the radius to 110 pixels
$c->setPieSize(280, 135, 110);

# Draw the pie in 3D with 20 pixels 3D depth
$c->set3D(20);

# Use the side label layout method
$c->setLabelLayout(SideLayout);

# Set the label box background color the same as the sector color, with glass effect,
# and with 5 pixels rounded corners
$t = $c->setLabelStyle();
$t->setBackground(SameAsMainColor, Transparent, glassEffect());
$t->setRoundedCorners(5);

# Set the border color of the sector the same color as the fill color. Set the line
# color of the join line to black (0x0)
$c->setLineColor(SameAsMainColor, 0x000000);

# Set the start angle to 135 degrees may improve layout when there are many small
# sectors at the end of the data array (that is, data sorted in descending order). It
# is because this makes the small sectors position near the horizontal axis, where
# the text label has the least tendency to overlap. For data sorted in ascending
# order, a start angle of 45 degrees can be used instead.
$c->setStartAngle(135);

# Set the pie data and the pie labels
$c->setData($data, $labels);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

  Re: Pie charts
Posted by Peter Kwan on May-29-2009 02:51
Hi Summaria,

If your code does not display a graph, please let me know what does it display, or what is the error message?

If the browser screen is completely blank, it may be because you have configured your PHP not to display error messages. Please configure your PHP to display error messages, so you can see the error message. For example, please modify your "php.ini" to use the following configuration (if it is not already using this configuration), and **restart** your web server.

display_errors = On
error_reporting = E_ALL

Also, to diagnose the problem, please remove your database code, or completely comment it out (you should start commenting the code out from the line "$hostname="localhost;"). If the chart works without the database code, it means the database code has some errors. Please create a separate page to debug the databaes code first, like:


<?php

#file to debug the database code

$hostname="localhost";
$mysql_login="root";
$mysql_password="";
$database="rttanalyzer";
// connect to the database server
if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
  die("Can't connect to database server.");
}else{

echo "Database connection successfull<br>";

  // select a database
    if (!(mysql_select_db("$database",$db))){
     die("Can't connect to database.");
    }
}
$sql=mysql_query("select source_ip,protocol from statistics order by ID");

$tcp=0;
$udp=0;
$othr=0;
while($row=mysql_fetch_array($sql))
{
$data =$row["protocol"];

if($data==6)
$tcp++;
else if($data==17)
$udp++;
else
$othr++;



}
?>
<HTML><BODY>
TCP = <?php echo $tcp; ?><BR>
UDP = <?php echo $udp; ?><BR>
OTHR = <?php echo $othr; ?>
</BODY></HTML>


Hope this can help.

Regards
Peter Kwan