我是 pchart 的新手,我在从 mysql 表创建图表时遇到了问题(可能是我错过了)。我想要的只是根据我将选择的项目绘制一行。它只工作了一次,然后每次我尝试再次运行脚本时,apache(我正在使用 apache2)给出超时并使用“top”检查服务器,进程 apache 使用 100% cpu 使用率。有时创建图表有时只是保持使用 100% 的 cpu 使用率并且什么都不做。如果我使用“autoOutput”方法在最后创建 .png 图像,则会出现错误,表示图像无法显示,因为它包含错误,但使用“Render”会创建图表,但有时正如我所解释的那样。以下是我的代码,希望有人能指点一下。
<?php
/* pChart library inclusions */
include("../../Library/class/pData.class.php");
include("../../Library/class/pDraw.class.php");
include("../../Library/class/pImage.class.php");
include "../../connection.php";
// Values from List.php
$Selected=$_POST['Selection'];
$MyData = new pData();
/* QUERY FOR THE CHART */
$Requete = "SELECT * FROM table WHERE Sector = '$Selected' LIMIT 0 , 30";
$Result = mysql_query($Requete,$db)or die(mysql_error());
while($row = mysql_fetch_array($Result))
{
$Sector = $row["Sector"];
$Current_reading = $row["Current_reading"];
$Old_Reading = $row['Old_reading'];
$Month_Consumption = $row['Month_Consumption'];
$Current_reading = $row['Current_reading'];
$DM = $row['DM'];
$FP = $row['FP'];
$Cost = $row['Cost_KWh_$90.0000'];
$MyData->addPoints($Current_reading,'Current_reading');
$MyData->addPoints($Old_Reading,'Old_reading');
$MyData->addPoints($Month_Consumption,'Month_Consumption');
$MyData->addPoints($DM,'DM');
$MyData->addPoints($FP,'FP');
$MyData->addPoints($Cost,'Cost_KWh_$90.0000');
}
/* Save the data in the pData array */
$MyData->setAbscissa("Consumos_de");
$MyData->setAbscissaName('February 2014');
$MyData->setSerieDescription($Sector,"Sectores");
$MyData->setAxisName(0,"Kw");
/* Create the pChart object */
$myPicture = new pImage(800,230,$MyData);
$myPicture->drawGradientArea(0,0,800,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,800,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
$myPicture->setFontProperties(array("FontName"=>"../../Library/fonts/verdana.ttf","FontSize"=>8));
/* Draw the scale */
$myPicture->setGraphArea(50,30,780,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(680,12,array("Style"=>LEGEND_BORDER,"Mode"=>LEGEND_VERTICAL));
/* Render the picture (choose the best way) */
$myPicture->Render("/var/www/images/YourGraph.png");
?>