2017-02-09 59 views
1

請溫和......Pchart在X軸上打印雙值

使用下面的代碼在RPI上使用pchart打印圖表會導致在X軸上雙擊打印的值。

我的首選結果是單個x軸值稍微旋轉,但無論我在下面的代碼中更改它不會給出好的結果。

幫助,將不勝感激!

莫里斯

<?php 

ini_set('display_errors', 'On'); 
error_reporting(E_ALL | E_STRICT); 

include("class/pDraw.class.php"); 
include("class/pImage.class.php"); 
include("class/pData.class.php"); 

$db = new PDO("sqlite:/home/pi/sensor.db"); 

$MyData = new pData(); 

$tijd=""; 
$lucht=""; 

$result = $db->query('SELECT tijd, lucht FROM waarden WHERE lucht > 40'); 
foreach($result as $row) 
{ 
    $tijd[] = $row["tijd"]; 
    $lucht[] = $row["lucht"]; 
} 

$MyData->addPoints($lucht,"lucht"); 
$MyData->setSerieOnAxis("lucht", 0); 
$MyData->setAxisName(0,"lucht"); 
$MyData->setAxisUnit(0,"%"); 

$MyData->addPoints($tijd,"tijd"); 
$MyData->setSerieDescription("tijd","Tijden"); 
$MyData->setAbscissa("tijd"); 

$myPicture = new pImage(800,330,$MyData); 
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11)); 
$myPicture->setGraphArea(60,40,740,290); 
$myPicture->drawScale(array("AutoAxisLabels"=>FALSE,"RemoveXAxis"=>FALSE)); 
$myPicture->drawLineChart(); 

//rotate the xaxis values 
$myPicture->drawScale(array("DrawSubTicks"=>False, "LabelRotation"=>20)); 

$myPicture->autoOutput("mypic.png"); 
$db = null; 
?> 

enter image description here

回答

0

找到了我自己的錯誤。

看來,我的雙指令

$myPicture->drawScale(array(" 

在初始化的,而不是處理得不好而導致雙X軸標籤

正確的代碼:

<?php 

ini_set('display_errors', 'On'); 
error_reporting(E_ALL | E_STRICT); 

include("class/pDraw.class.php"); 
include("class/pImage.class.php"); 
include("class/pData.class.php"); 

$db = new PDO("sqlite:/home/pi/sensor.db"); 

$MyData = new pData(); 

$tijd=""; 
$lucht=""; 

$result = $db->query('SELECT tijd, lucht FROM waarden WHERE lucht > 40'); 
foreach($result as $row) 
{ 
    $tijd[] = $row["tijd"]; 
    $lucht[] = $row["lucht"]; 
} 

$MyData->addPoints($lucht,"lucht"); 
$MyData->setSerieOnAxis("lucht", 0); 
$MyData->setAxisName(0,"lucht"); 
$MyData->setAxisUnit(0,"%"); 

$MyData->addPoints($tijd,"tijd"); 
$MyData->setAbscissa("tijd"); 
$MyData->setAbscissaName("Time of Reading"); 

$myPicture = new pImage(800,330,$MyData); 
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11)); 
$myPicture->setGraphArea(60,40,740,290); 

//Remove line below to avoid double Xaxis values 
//$myPicture->drawScale(array("AutoAxisLabels"=>FALSE,"RemoveXAxis"=>FALSE)); 
$myPicture->drawScale(array("DrawSubTicks"=>False, "LabelRotation"=>20)); 
$myPicture->drawLineChart(); 
$myPicture->autoOutput("mypic.png"); 
$db = null; 
?>