是否可以将Google图表保存为图片? [英] Is it possible to save a google chart as an image?

查看:116
本文介绍了是否可以将Google图表保存为图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个应用程序,我需要将google图表保存为图像。我所使用的是tomcat,servlets和javascript。有没有办法保存下面生成的图表作为图像? (参考帖子末尾的代码)。
的想法是,用户会看到这个图表,然后将有选项上传到他的Facebook个人资料。我不知道这是否可以上传到Facebook的原生格式或将需要保存为一个JPG。

I am making an application in which I would need to save the google chart as an image . All I am using is tomcat, servlets and javascript. Is there a way to save the following generated chart as an image? (refer to code at the end of post). The idea is that user would see this chart and then would have the option of uploading it to his facebook profile. I am not sure if this will be uploadable to facebook in its native format or will be needed to be saved as a jpg.

<html>    
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = new google.visualization.DataTable();

    data.addColumn('string', 'Year');
    data.addColumn('number', 'Sales');
    data.addRows(4);
    data.setValue(0, 0, ''+2004);
    data.setValue(0, 1, 1000);
    data.setValue(1, 0, '2005');
    data.setValue(1, 1, 1170);
    data.setValue(2, 0, '2006');
    data.setValue(2, 1, 860);
    data.setValue(3, 0, '2007');
    data.setValue(3, 1, 1030.5);

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, {width: 400, height: 240, title: 'Company Performance',hAxis: {title: "X", titleTextStyle: {color: "green"}}});
  }

</script>
  </head>

  <body>
    <div id="chart_div"></div>
  </body>
</html>


推荐答案

这个功能最近似乎是 1 添加为:

It looks like this feature was recently1 added as:

chart.getImageURI()

请参阅文档

1 它似乎是在2014年1月29日版本中添加的。

1It appears to have been added in the Jan 29, 2014 release.

这篇关于是否可以将Google图表保存为图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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