Pchart 在 X 轴上打印双精度值
Pchart prints double values on X-axis
温柔点..
使用下面的代码在 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
发现我自己的错误。
看来我的双重指令
$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;
?>
温柔点..
使用下面的代码在 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
发现我自己的错误。
看来我的双重指令
$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;
?>