error in creating more charts in looping - php
I'm trying to create country based charts. i'm using pchart for this, because it will create charts as image by default.
I've created a function which creates barchart. I'm selecting countries and its stats and passing it to the barchart function which creates a chart as a flat file.
When i pass a single a country stats it is creating chart. the problem is when i try to post more than one country, it is creating only one country image not more than that. i don't know where the issue exists? Help appreciated.
sample code is here:
<?php
$con=mysql_connect("localhost","root","");
$ln=mysql_select_db("conif_new",$con);
$qry="select country from chart group by country limit 2";
$cnlist=mysql_query($qry);
while($row=mysql_fetch_row($cnlist)){
$cn=$row[0];
$nqry="select server,count(*) from chart where country='$cn' group by server";
$dset=mysql_query($nqry);
$x="";
$xt="";
while($crow=mysql_fetch_row($dset)){
$x.=$crow[1].",";
$xt.=$crow[0].",";
}
$x=substr($x,0,strlen($x)-1);
$xt=substr($xt,0,strlen($xt)-1);
//echo "$x**$xt<br>";
if(barChart($x,$xt,$cn)开发者_Go百科){}
}
function barChart($x,$xt,$name){
$x=explode(",",$x);
$xt=explode(",",$xt);
/* CAT:Bar Chart */
/* pChart library inclusions */
include("class/pData.class.php");
include("class/pDraw.class.php");
include("class/pImage.class.php");
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($x,"Server A");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints($xt,"Months");
$MyData->setSerieDescription("Months","Month");
$MyData->setAbscissa("Months");
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,
"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,
"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
$myPicture->setFontProperties(array("FontName"=>"fonts/verdana.ttf","FontSize"=>9));
/* Draw the scale */
$myPicture->setGraphArea(50,30,680,200);
$myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,
"GridAlpha"=>10));
/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the chart */
$settings = array("Gradient"=>TRUE,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,
"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
$myPicture->drawBarChart($settings);
/* Write the chart legend */
$myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Render the picture (choose the best way) */
//$myPicture->autoOutput("pictures/example.drawBarChart.shaded.png");
if($myPicture->render("C:/wamp/www/chart/".$name.".png"))
echo "true";
else
echo "false";
}
?>
I found an answer!!!, just noticed "include statements" inside barchart function. Removed it, Thats it!
I should've placed "include_once" instead of "include" or should've moved the "include" statements outside the function to make it work.
精彩评论