我想将一个函数称为图像src。我正在使用phpgraphlib绘制图形。我试过这样但得到了垃圾值。 `
<?php
include("phpgraphlib.php");
function kk()
{
$graph=new PHPGraphLib(1000,1000);
include("db_connect.php");
$dataArray=array();
$graph_array=array();
$sql="SELECT name,mark,entered_time FROM student ";
$result = mysql_query($sql,$con) ;
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$without_comma_value=explode(',', $row['mark']);
$count=count($without_comma_value);
for($i=0;$i<$count;$i++)
{
$Val_onebyone= $without_comma_value[$i];
$num=$i+1;
$dataArray[$num]=$Val_onebyone;
}
}
}
$graph->setBackgroundColor("#F78181");
$graph->addData($graph_array);
$graph->setBars(false);
$graph->setLine(true);
$graph->setupYAxis(20, 'black');
$graph->setupXAxis(20, 'black');
$graph->setTextColor('black');
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->setLineColor('maroon');
$graph->createGraph();}
?>
<html>
<form>
<div align="center">
<table><tr>
<td valign="mid"><b>SpO2</b></td>
<td align="center">
<img src="<?php echo kk(); ?>" />
</td>
</tr></table>
</div>
<form>
`当在另一个php页面上编写此图形创建函数并尝试将该页面称为img src时,图形正在正常运行。但我想把它称为功能。请帮忙
答案 0 :(得分:0)
createGraph()
直接写入PHP的输出管道。你需要缓存它并回显它。
更改最后两行
$graph->setLineColor('maroon');
$graph->createGraph();}
进入这个:
$graph->setLineColor('maroon');
ob_start();
$graph->createGraph();
$out = ob_get_clean();
echo $out;
}