【问题标题】:Working with TeeChart DateTime on XAxis在 XAxis 上使用 TeeChart DateTime
【发布时间】:2017-02-20 15:23:10
【问题描述】:

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

【问题讨论】:

    标签: php teechart


    【解决方案1】:

    产品附带的功能演示中的“CandleChart.php”示例在横轴上使用日期时间。
    这里有一个变体:

    <?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.'">';                
    ?>
    

    【讨论】:

      【解决方案2】:

      问题是我没有固定的时间间隔,也不能像 Candle 示例那样使用“时间机器”。

      我得到的时间(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;
          }
      

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

      最好的问候。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多