【问题标题】:pChart:render the image to browser and embed in htmlpChart:将图像渲染到浏览器并嵌入到html中
【发布时间】:2013-12-25 10:47:20
【问题描述】:

我有一个类名“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,因此我无法在单独的页面中呈现图像。 对不起我的英语不好!但我需要你的帮助!谢谢你!

【问题讨论】:

    标签: html embed pchart


    【解决方案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 页面中。

    【讨论】:

    • 你是对的!渲染一个临时图像可以解决我的问题。但我不想将图片存储在我的网络服务器中!我已经找到了一个看起来很愚蠢的解决方案!谢谢!
    • @tudouya 好的,如果您找到不同的解决方案,请将其作为答案发布在这里,因为我有兴趣自己找到答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多