Is it possible to save a google chart as an image?(是否可以将谷歌图表保存为图像?)
问题描述
我正在制作一个应用程序,我需要将谷歌图表保存为图像.我使用的是tomcat、servlet 和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="aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS9qc2FwaQ=="></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.
这篇关于是否可以将谷歌图表保存为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以将谷歌图表保存为图像?


- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01