在XAxis上使用TeeChart DateTime
问题描述:
我有一个Oracle查询返回格式为Y-m-d H:i:s的日期字符串,我需要将它们传递给Series::AddXY method
。我怎样才能做到这一点?在XAxis上使用TeeChart DateTime
答
的问题是,我没有固定的时间间隔,我不能用一个“时间机器”在蜡烛的例子。
(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;
}
我希望这可以帮助其他人。
此致敬礼。
答
产品附带的功能演示中的“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.'">';
?>