简体   繁体   English

如何在php中将图形创建函数称为img src?

[英]how to call a graph creating function in php as img src?

I wants to call a function as image src.I am drawing graph using phpgraphlib. 我想将函数称为图像src。我正在使用phpgraphlib绘制图形。 I have tried like this but getting junk values . 我已经尝试过这种方法,但是却得到了垃圾值。 ` `

        <?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>

`When write this graph creating function on another php page and try to call that page as img src , graph is getting properly. `当在另一个PHP页面上编写此图创建函数并尝试将该页面作为img src调用时,图会正确显示。 But I want to call it as function . 但是我想把它称为函数。 please help 请帮忙

createGraph() writes directly into the output pipe of PHP. createGraph()直接写入PHP的输出管道。 You need to cache this and echo it. 您需要缓存它并回显它。

Change this last two lines 更改最后两行

  $graph->setLineColor('maroon');
  $graph->createGraph();}

into this: 到这个:

  $graph->setLineColor('maroon');
  ob_start();
  $graph->createGraph();
  $out = ob_get_clean();
  echo $out;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM