pChart:将图像渲染到浏览器并嵌入到html中

时间:2013-12-25 10:47:20

标签: html embed pchart

我有一个类名'MonthReport.class.php'及其结构如下:

    class MonthReport{
    .....
    //some member variables


    public function pieChart(){
      ........
      //the image data comes from mysql and data belongs to a specified user
      $myPicture->Stroke();
   }

   public function lineChart(){
      ........
      //the image data comes from mysql and data belongs to a specified user
      $myPicture->Stroke();
  }

   public function render html(){
    $html.=str1<<<
    .....
    //some html code
str1;
   $html.=<<<str2
   <img src="$this->pieChart()" />    //can not work
str2;
  }
}

当我在地方src中调用pieChart()函数时,它将覆盖我的整个页面并显示图像。我可以这样做吗? 我尝试在单独的页面中渲染图像,但图像需要一些指定的用户数据,例如'userId'。在其他单词中,当我新建一个对象时,它指定userId,因此我无法在单独的页面中渲染图像。 抱歉我的英语不好!但我需要你的帮助!谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

你的问题有点不清楚,但如果你的问题是我的假设,那么我曾经有类似的问题(图形创建只是一个图像,其他所有页面内容都没有显示)。我的解决方案是使用pchart生成临时图像,然后将该文件嵌入到html

 $myfilename = "temp_image.png";      // temp file name
 $myPicture = new pImage(700,500,$myData);  

 // other image creation code....


 $myPicture->Render($myfilename);     // generate image "temp_image.png"
 $image_html = '<img src="' . $myfilename . '">';   //generate the link
 print("$htmlline");

由于你的问题不清楚,这里还有一些猜测。以上内容适用于我,并且可以将pChart动态创建的图像嵌入到我的php页面中。