Google图表为图片 [英] Google Charts as Image
问题描述
我想使用Google图表在图表中嵌入电子邮件中的图片。所以每个用户都有一个唯一的图。
I am trying to use Google charts to embed images of charts in the emails. So Each user will have a unique graph.
我们可以使用API并嵌入一个唯一的网址,用于呈现图表并将图片发送到电子邮件客户端。
Can we use the API and embed a unique URL that will render the Charts and deliver an Image to the email Client.
推荐答案
可以使用 Google图表向导。不过,这种服务最近(我相信4月)因为已经过时了。
It is possible to generate a url that will render an image of a chart using the Google Chart Wizard. However, that service recently (April I believe) because deprecated. It still works fine, but for a long term solution, you may have to come up with another method.
编辑
另一种方法是在发送电子邮件之前生成图像并将其保存到服务器。您可以通过在服务器上拥有一个专门用于通过解析给定的段落生成图表的页面,并且在加载图表时发送带有图像数据的POST请求。您可以使用隐藏的画布(需要HTML5)和 canvg javascript来访问数据URI plugin:
Another method would be to generate the image and save it to your server before sending the email. You can do this by having a page on your server dedicated to generating the chart by parsing a given slug, and when the chart is loaded send a POST request with the image data. You can access the data URI by using a hidden canvas (HTML5 is required) and the canvg javascript plugin:
chart_area = document.getElementById("chart_div").getElementsByTagName('iframe')[0].contentDocument.getElementById("chartArea");
svg = chart_area.innerHTML;
canvas = document.getElementById("hidden_canvas");
canvas.setAttribute('width', chart_area.offsetWidth);
canvas.setAttribute('height', chart_area.offsetHeight);
canvg(canvas, svg);
image_data_uri = canvas.toDataURL("image/png");
这篇关于Google图表为图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!