Create Google Charts & Convert to Images Server Side

与世无争的帅哥 提交于 2019-12-24 05:19:39

问题


I currently have google charts implemented at several places on my site and I can convert them to images and download them. That was easy.

Now I'm hoping to create these charts and convert them to images all on the server.

I've done a lot of searching and I've come up with no examples of this, and no questions either, which is starting to make me think it's not possible.

I know that these charts are normally created at runtime with javacript in the client's browser, so I guess I'm wondering if there's a way to run the google chart javascript on my server without a browser, and create and save these images?

I was told about server side javascript yesterday, until then I had no idea it existed, but could this be an option?

Is there a way to emulate a browser in .NET and output an image? Can I run a browser on the server and get the image?

Is there another way to do this?

Or is this idea just impossible?


回答1:


One option you have is using a headless browser to execute the code locally and then extract the image from there. Take a look at PhantomJS examples to see what's possible

http://phantomjs.org/examples/

If you need to run this occasionally it would be OK just using stand-alone phantomjs on every request you need it, but if you are going to use it often, take a look at the screenshot projects listed here http://phantomjs.org/related-projects.html

Some of them start a node server so you don't need to start phantom all the time and it will save you runtime. It's only worth the effort if you tried first the stand alone solution and found it too slow




回答2:


PhantomJS is an option that works well. My team at vida.io has developed a cloud-based solution to generate image for website. It is optimized for svg (in particular d3.js data visualization). But it can be used to generate image for any element within website.

Check out our web interface:

http://image.vida.io/

You can use our server or run your own. Server stack is nodejs.



来源:https://stackoverflow.com/questions/20564023/create-google-charts-convert-to-images-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!