Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在循环中创建更多图表时出错-php_Php_Loops_Charts_Pchart - Fatal编程技术网

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

在循环中创建更多图表时出错-php,php,loops,charts,pchart,Php,Loops,Charts,Pchart,我正在尝试创建基于国家的图表。我使用pchart来实现这一点,因为默认情况下,它会将图表创建为图像 我创建了一个创建条形图的函数。我正在选择国家及其统计数据,并将其传递给条形图函数,该函数将创建一个平面文件形式的图表 当我通过一个国家的统计数据时,它正在创建图表。问题是,当我尝试发布多个国家的帖子时,只会创建一个国家的形象,而不是更多。我不知道问题在哪里?谢谢你的帮助 示例代码如下: <?php $con=mysql_connect("localhost","root",""); $ln=

我正在尝试创建基于国家的图表。我使用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”语句移到函数之外以使其工作。

是否有任何错误?请在第二行插入一个
错误报告(E\u ALL)
。即使我输入了错误报告(E\u ALL),它也不会显示任何错误。但它只创建了第一张图表。随机点,我认为这与问题无关。但是使用return true和return false而不是回显字符串。当您实际返回true或false而不是简单地回显字符串时,它会做什么?还请通过添加
echo“handling$name\n”
或类似内容来检查while循环是否实际运行了多次。