gpt4 book ai didi

php - 使用 pchart 创建的图表超时

转载 作者:行者123 更新时间:2023-11-30 00:08:34 24 4
gpt4 key购买 nike

我是 pchart 新手,在从 mysql 表创建图表时遇到问题(可能是我错过的问题)。我想要的只是根据我要选择的项目绘制一行图表。它只工作了一次,然后每次我尝试再次运行脚本时,apache(我使用的是apache2)都会超时并使用“top”检查服务器,进程apache使用100%的CPU使用率。有时,图表创建后有时只是保持 100% 的 CPU 使用率,什么也不做。如果我使用“autoOutput”方法创建 .png 图像,最后会出现一个错误,表示该图像无法显示,因为它包含错误,但使用“渲染”会创建图表,但有时正如我所解释的那样。以下是我的代码,希望有人能给一些启发。

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

最佳答案

嗯,这样做就成功了:

我将以下所有内容移出了 while 循环:

$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');

最后我改变了

$myPicture->Render("/var/www/images/YourGraph.png");  

并添加了这个:

$myPicture->autoOutput("YourChart.png");

我必须对我试图绘制图表的信息进行更多排序,但导致 100% CPU 使用率的问题得到解决,图表也出现了。这确实是我接触 PHP 的第一步,对于这里的困惑,我深表歉意。希望这对某人有帮助。

关于php - 使用 pchart 创建的图表超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24290815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com