dongpan8439 2017-02-09 04: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 01: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部