在 XAxis 上使用 TeeChart DateTime

Working with TeeChart DateTime on XAxis

我有一个 Oracle 查询,其中 returns 格式为 Y-m-d H:i:s 的日期字符串,我需要将它们传递给 Series::AddXY method。我该怎么做?

产品随附的功能演示中的 "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.'">';                
?>

问题是我没有恒定的时间间隔,我不能像蜡烛示例中那样使用 "time machine"。

我的时间(X 值)来自 Oracle 查询:

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

因此 DateTime 值是 PHP 日期格式的字符串:Y-m-d 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;
    }

我希望这可以帮助其他人。

此致。