在浏览器中将Google Geochart转换成图像(JPEG,PNG等)或PDF [英] Convert Google Geochart to image (JPEG, PNG, etc.) or PDF in the browser

查看:182
本文介绍了在浏览器中将Google Geochart转换成图像(JPEG,PNG等)或PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google GeoCharts(https://developers.google.com/chart/interactive/docs/gallery/geochart#Overview)在浏览器中动态生成颜色编码的地图。 geochart api绘制地图使用javascript / svg ...任何建议生成可导出的图像文件? (pdf,光栅图像等)

I'm using Google GeoCharts (https://developers.google.com/chart/interactive/docs/gallery/geochart#Overview) to dynamically generate color-coded maps in the browser. The geochart api draws the maps using javascript/svg... any advice for generating an exportable image file? (pdf, raster image, etc.)

可以通过google geocharts来完成吗?如果没有,是否有另一项服务可以推荐?

Can this be done through google geocharts? If not, is there another service you can recommend?

*我们以前使用GeoMaps,但分辨率不合适。

*We were previously using GeoMaps but the resolution was not suitable.

推荐答案

可以按照此页面。请注意,文章中的代码是基于使用iframe的旧版Google Visualization,并且不会发布。但是,您可以使用以下代码(在注释中找到)执行相同操作:

This can be done by following the steps on this page. Note that the code in the article is based on an old version of Google Visualization which used iframes, and will not work as posted. However, you can do the same using the following code (found in the comments):

var svg = $(chartContainer).find('svg').parent().html();
var doc = chartContainer.ownerDocument;
var canvas = doc.createElement('canvas');
canvas.setAttribute('style', 'position: absolute; ' + '');
doc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL("image/png");
canvas.parentNode.removeChild(canvas);
return imgData; 

注意:我没有创建这个代码,它最初是由上述网站的作者创建的Riccardo Govoni),并在用户Thomas的评论部分更新。

Note: I did not create this code, it was originally created by the author of the above site (Riccardo Govoni) and updated in the comments section by user Thomas.

这篇关于在浏览器中将Google Geochart转换成图像(JPEG,PNG等)或PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆