2011-09-10 10 views
0

我正在嘗試創建基於國家/地區的圖表。我爲此使用了pchart,因爲它默認會將圖表創建爲圖像。在循環中創建更多圖表時出錯 - php

我創建了一個創建條形圖的函數。我選擇國家及其統計數據並將其傳遞給條形圖函數,該函數將平面圖創建爲平面文件。

當我通過一個國家統計它正在創建圖表。問題是,當我嘗試發佈多個國家時,它只創建一個國家形象不超過。我不知道問題存在的地方?幫助讚賞。

示例代碼是在這裏:

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

有沒有錯誤?請在第二行插入一個'error_reporting(E_ALL)'。 – ComFreek

+0

它甚至沒有顯示任何錯誤,我把error_reporting(E_ALL)。但它只創建第一個圖表。 – VKGS

+0

隨機點,而不是我認爲它與問題相關。但是使用return true並返回false而不是echo'ing一個字符串。 –

回答

0

我找到了答案!!!,只注意到 「包括報表」 條形圖函數內。刪除它,這就是它!

我應該放置「include_once」而不是「include」,或者應該將「include」語句移到函數外部以使其工作。

+0

我必須等兩天才能接受我自己的答案... – VKGS