dtkvlj5386
dtkvlj5386
2010-08-26 22:55

如何存储$ chart-> draw()的结果; 变量?

已采纳

I'm using the succinctly named googlechartseasyphpclass script to generate google charts from numbers I'm grabbing from a database. After the charts are generated, I want to put the results in a different table. The way you generate a Google Charts URL using the easyphpclass script is like this:

$chart=new googleChart(null,'line',$title,'500x200');
$chart->loadData($chartData);
$chart->setLabels($axislabel);
$chart->draw(); 

That last line is tripping me up. I can't shove the URL it produces into a variable so I can put it in a database table. It just draws the chart on the screen. Is there a good way of taking that value and making it something I can use? Thanks!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongleiqiao4906 dongleiqiao4906 11年前

    From the documentation you linked, it'll echo a <img> tag if the first parameter is true (which it is by default) and will return a url if the first parameter is false. Thus you could do something like:

    $chart_url = $chart->draw(false);
    

    Or capture the entire <img> tag:

    $chart_img_tag = '<img src="' . $chart->draw(false) . '" />';
    

    You could use output buffering but for something like this it's really unnecessary overkill because it's trivial to output your own <img> tag.

    点赞 评论 复制链接分享