我想绘制一个图表,其中将从MySQL数据库中获取值。它不起作用。但是,如果我给出手动值,那么图表就会显示出来。以下是我的代码:
<?php
include "libchart/classes/libchart.php";
header("Content-type: image/png");
$chart = new LineChart();
$con=mysqli_connect("localhost","root","","bkash");
$result = mysqli_query($con,"SELECT time,trx_value FROM dialer_rate where mno='tnr'");
$serie1 = new XYDataSet();
while($row = mysqli_fetch_array($result))
{
$serie1->addPoint(new Point($row['time']->time, $row['trx_value']->trx_value));
}
$dataSet = new XYSeriesDataSet();
$dataSet->addSerie("TNR", $serie1);
$dataSet->addSerie("ROBI", $serie2);
$dataSet->addSerie("LNK", $serie3);
$dataSet->addSerie("AIR", $serie4);
$chart->setDataSet($dataSet);
$chart->setTitle("bKash Success/Failure for All MNO");
$chart->getPlot()->setGraphCaptionRatio(0.62);
$chart->render();
&GT;
我没有及时获得任何价值。下面的行中的trx_value ...
while($row = mysqli_fetch_array($result))
{
$serie1->addPoint(new Point($row['time']->time, $row['trx_value']->trx_value));
}
但是如果我想使用下面的输出打印值
while($row = mysqli_fetch_array($result))
{ echo $row['time'];
echo $row['trx_value'];
};
然后输出即将来临..
当我使用下面的手动值时,也会显示图表。
$serie1->addPoint(new Point("06-01", 273));
$serie1->addPoint(new Point("06-02", 421));
$serie1->addPoint(new Point("06-03", 642));
$serie1->addPoint(new Point("06-04", 799));
$serie1->addPoint(new Point("06-05", 1009));
$serie1->addPoint(new Point("06-06", 1106));
答案 0 :(得分:0)
你$row['time']->time
周围的引号不应该在那里,看起来你正在尝试&#34;双索引&#34;您的列(即使用['field']
和->field
获取值)。
new Point("$row['time']->time", $row['trx_value']->trx_value)
应该是
new Point($row['time'], $row['trx_value'])
请注意Stack Overflow的语法高亮显示器如何提出第一个问题。如果你的文本编辑器不支持语法高亮显示,那么切换到那个可能是值得的。