doulu1325 2014-10-07 10:45
浏览 50

如何在php中调用图形创建函数作为img src?

I wants to call a function as image src.I am drawing graph using 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. But I want to call it as function . please help

  • 写回答

1条回答 默认 最新

  • douqin231881 2014-10-07 11:02
    关注

    createGraph() writes directly into the output pipe of 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;
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程