dongpan8439 2017-02-09 12:52
浏览 32
已采纳

Pchart在X轴上打印双倍值

Be gentle..

Using the code below for printing a chart using pchart on a RPI results in the values double printed on the X-axis.

My preferred outcome would be single x axis values slightly rotated but whatever I change in the code below it does not give the good result.

Help would be appreciated!

Maurice

<?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

  • 写回答

1条回答 默认 最新

  • doq8211 2017-02-12 09:46
    关注

    Found my own error.

    It seems that my double instruction

    $myPicture->drawScale(array("
    

    in the initialization at the and isn't handled too well and results in a double Xaxis label

    The correct code:

    <?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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)