0
對於pchart來說我是新手,我從mysql表中創建圖表時遇到了問題(可能是我錯過了)。我想要的是根據我選擇的項目繪製一行圖表。這隻有一次,然後每次我嘗試再次運行腳本時,apache(我使用的是apache2)會給出超時並使用「top」檢查服務器,但apache使用100%的cpu使用率。某些時候,圖表創建了一些時間,它只是保持100%的CPU使用率,並且什麼都不做。如果我使用「autoOutput」方法創建.png圖像,最後一個錯誤表示圖像無法顯示,因爲它包含錯誤,但使用「渲染」圖表創建,但有時候正如我解釋的那樣。以下是我的代碼,希望有人能給我點亮。使用pchart創建的圖表會給出超時
<?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");
?>