Search code examples
phpteechart

Working with TeeChart DateTime on XAxis


I have an Oracle query which returns date string in the format Y-m-d H:i:s and I need to pass them to the Series::AddXY method. How can I do that?


Solution

  • The problem is that I do not have constant time intervals and I can not use a "time machine" as in the Candle example .

    The time (X value) I have comes from an Oracle query:

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

    So the DateTime value is a string in the PHP date format : Y-m-d H:i:s, which I need to convert to TChart values. I do not know if I am full correct but it seems that DateTime values should be entered as float values (Unix Timestamp)

    So I am converting them as follows:

        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;
        }
    

    I hope this can help someone else.

    Best regards.