2017-02-20 83 views

回答

0

的問題是,我沒有固定的時間間隔,我不能用一個「時間機器」在蠟燭的例子。

(X值)我有來自於Oracle查詢時間:

$query = "SELECT ptm.IDENTIFICACAO, 
      mtr.SERIAL, 
      TO_CHAR(rtu.DATAHORA, 'yyyy-mm-dd hh24:mi:ss') AS DATAHORA, 

所以DateTime值是在PHP日期格式的字符串:年月日H:I:S,我需要轉換到TChart值。我不知道我是否完全正確的,但它 似乎如下DateTime值應輸入爲浮點值(UNIX時間戳)

所以我把它們轉換:

while(($row = oci_fetch_array($stmt, OCI_ASSOC)) != false){ 
     $thetime = DateTime::createFromFormat('Y-m-d H:i:s', $row["DATAHORA"]); 


     if($thetime) 
      $tchart->getChart()->getSeries(0)->addXY((float) $thetime->getTimestamp() , $row["ENERTOT"]/1000); 
     } 
     ++$rowCount; 
    } 

我希望這可以幫助其他人。

此致敬禮。

1

產品附帶的功能演示中的「CandleChart.php」示例在水平軸上使用DateTimes。
這裏的變化:

<?php 
     //Includes 
     include "../../../../sources/TChart.php"; 

     $chart1 = new TChart(600,450); 
     $chart1->getChart()->getHeader()->setText("Candle Style"); 
     $chart1->getChart()->getAspect()->setView3D(false); 
     // Clip Series points 
     $chart1->getChart()->getAspect()->setClipPoints(true); 
     $chart1->getChart()->getLegend()->setVisible(false); 

     // Add Candle data using doubles for date values 
     $today = time(); 
     $day = 86400; 
     $hour = 3600; 

     $chart1->getAxes()->getBottom()->setIncrement(DateTimeStep::$ONEMINUTE); 
     $chart1->getAxes()->getBottom()->getLabels()->setDateTimeFormat('d/m/Y H:i:s'); 
     $chart1->getAxes()->getBottom()->getLabels()->setAngle(90); 
     $candle=new Candle($chart1->getChart()); 

     $chart1->setAutoRepaint(false); 
     for ($i=$today;$i<($today+$hour);$i+=60) { 
      $candle->addCandle($i,rand(0,100),rand(0,100),rand(0,100),rand(0,100)); 
     } 
     $chart1->setAutoRepaint(true); 
     $chart1->doInvalidate(); 

     $chart1->render("chart1.png"); 
     $rand=rand(); 
     print '<font face="Verdana" size="2">Candle Chart Style<p>'; 
     print '<img src="chart1.png?rand='.$rand.'">';     
?>