简体   繁体   English

调用Google Visualization API服务器端

[英]Calling Google Visualization API Server-Side

I'm working on a project that involves exporting some HTML reports on a website into PDF format. 我正在一个项目中,该项目涉及将网站上的一些HTML报告导出为PDF格式。 I'd like to use the excellent flying-saucer Java library to do this but my major stumbling block is that several of these reports use the Google Visualization API to generate charts with JavaScript. 我想使用出色的飞碟Java库来执行此操作,但我的主要绊脚石是,其中一些报告使用Google Visualization API生成带有JavaScript的图表。 Flying-saucer doesn't currently support parsing/executing JS, so those charts don't show up in the generated PDF file. Flying-saucer当前不支持解析/执行JS,因此这些图表不会显示在生成的PDF文件中。

I was hoping to work around this by seeing if there was some kind of web service I could call instead via server-side code that would return the chart image in Base64 as a variable that I could reference in my view instead of getting it via JS. 我希望通过查看是否可以通过服务器端代码来调用某种Web服务来解决此问题,该服务器端代码会将Base64中的图表图像作为变量返回,可以在我的视图中引用,而不是通过JS来获取。 。

The old Google Image Charts API is exactly what I'm looking for, but it has unfortunately been deprecated and it looks like it's slated to be removed completely by next year, so it's not an option. 我一直在寻找旧的Google Image Charts API ,但不幸的是它已被弃用,并且似乎已定于明年完全删除,因此这不是一种选择。

I'm hoping Google has a newer alternative. 我希望Google有一个更新的替代方案。 If not, is there some other method that's recommended? 如果不是,是否建议使用其他方法? Thanks! 谢谢!

You can call the getImageURI method of the chart to generate an image/octet stream URI. 您可以调用图表的getImageURI方法来生成图像/八位字节流URI。 You can send that data to your server, and you should be able to reconstruct the chart as a .png image file. 您可以将该数据发送到服务器,并且应该能够将图表重构为.png图像文件。 I've never tried to do this server-side, so I'm not sure precisely how you would go about it, but this java tutorial might be of some assistance to you: http://www.programcreek.com/2009/02/java-convert-image-to-byte-array-convert-byte-array-to-image/ 我从未尝试过在服务器端进行此操作,因此我不确定您将如何使用它,但是此Java教程可能会对您有所帮助: http : //www.programcreek.com/2009/ 02 / java的转换图像到字节阵列变频-字节阵列到图像/

Years ago I wrote Eastwood Charts which implemented the Google Image Charts API as a servlet, backed by JFreeChart , so that you could generate charts without having to rely upon Google, or send your data to their servers. 多年前,我写了Eastwood Charts ,它以JFreeChart为后盾,将Google Image Charts API实现为servlet,这样您就可以生成图表而不必依赖Google或将数据发送到其服务器。 :-) :-)

I don't maintain Eastwood Charts anymore (like Google, I can't be relied upon either) but it is open source and the code works so you might find it helpful. 我不再维护Eastwood Charts(像Google一样,我也不能依靠),但是它是开源的并且代码有效,因此您可能会发现它很有用。 You could also modify it to meet your own requirements, which is something that wasn't possible with the Google service. 您也可以对其进行修改以满足自己的要求,而Google服务无法做到这一点。

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

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