开发者

How do I store the results of $chart->draw(); to a variable?

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(); 

开发者_StackOverflow中文版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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜