在循环- php中创建更多图表时出错


error in creating more charts in looping - php

我正在尝试创建基于国家的图表。这里我使用pchart,因为它默认会将图表创建为图像。

我创建了一个创建条形图的函数。我选择国家和它的统计数据,并将其传递给条形图函数,它创建一个图表作为平面文件。

当我通过一个单一的国家统计它正在创建图表。问题是当我试图发布多个国家时,它只创建一个国家的形象,而不是更多。我不知道问题出在哪里?帮助感激。

示例代码如下:

<?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)){}

}
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"; 
}
?>

我找到答案了!!我注意到在柱状图函数中有"include statements"。去掉它,就是它!

我应该把"include_once"而不是"include",或者应该把"include"语句移出函数以使其工作