简体   繁体   English

Google图表导出为图像

[英]Google Charts export as image

I'd like to get simple pie google chart (like this one https://developers.google.com/chart/interactive/docs/gallery/piechart ) and set to PDF as image. 我想获取简单的Google饼图(例如https://developers.google.com/chart/interactive/docs/gallery/piechart ),并设置为PDF作为图像。

To create PDF I use laravel-dompdf, which is a laravel wrapper for DOMPDF library. 要创建PDF,我使用laravel-dompdf,它是DOMPDF库的laravel包装器。 This library doesn't support javascript. 该库不支持javascript。

It should be in background. 它应该在背景中。 I mean that I don't have step where I display html in browser to save charts as image from javascript. 我的意思是,我没有在浏览器中显示html的步骤,无法将图表另存为来自javascript的图像。

Any hints? 有什么提示吗? It's also possible to use different similar library but I could not found nothing interesting. 也可以使用其他类似的库,但是我找不到任何有趣的东西。

Thanks in advance. 提前致谢。

Google offers a function called getImageURI() for its charts. Google为其图表提供了一个名为getImageURI()的函数。 This will return the chart as an image but in base64 encoded format. 这将以图表形式但以base64编码格式返回图表。 It's described under https://developers.google.com/chart/interactive/docs/printing . https://developers.google.com/chart/interactive/docs/printing下进行了描述。 Using this and a headless broswer such as PhantomJS you can get that base64 encoded image. 使用它和无头浏览器(例如PhantomJS),您可以获取该base64编码的图像。

You can use https://github.com/jonnnnyw/php-phantomjs to load the webpage with the chart on it and then fetch the base64 encoded image from that website. 您可以使用https://github.com/jonnnnyw/php-phantomjs加载带有图表的网页,然后从该网站获取base64编码的图像。

I would implement a javascript function that posts the base64 string to an endpoint and then you will be able to save that as a pdf/png/jpg or in any other formats. 我将实现一个将base64字符串发布到端点的javascript函数,然后您就可以将其另存为pdf / png / jpg或任何其他格式。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM