我尝试使用getImageURI方法提取图像但没有运气。
以下是我的代码:
var chart = new google.visualization.AnnotationChart(document.getElementById('temperature_chart'));
google.visualization.events.addListener(chart, 'ready', function () {
var imgUri = chart.getImageURI();
document.getElementById('chartImg').src = imgUri;
});
chart.draw(data, options);
答案 0 :(得分:0)
我不知道PDF但是图像是可能的:
<script type="text/javascript" src="http://canvg.github.io/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/StackBlur.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/canvg.js"></script>
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode;
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
var canvas = doc.createElement('canvas');
canvas.setAttribute('width', chartArea.offsetWidth);
canvas.setAttribute('height', chartArea.offsetHeight);
canvas.setAttribute(
'style',
'position: absolute; ' +
'top: ' + (-chartArea.offsetHeight * 2) + 'px;' +
'left: ' + (-chartArea.offsetWidth * 2) + 'px;');
doc.body.appendChild(canvas);
canvg(canvas, svg);
var imgData = canvas.toDataURL("image/png");
canvas.parentNode.removeChild(canvas);
return imgData;
}
document.body.addEventListener("load", function() {
saveAsImg( document.getElementById("pie_div")); // or your ID
}, false );
有关详细信息,请参阅此链接:Save Google charts as a image http://www.battlehorse.net/page/topics/charts/save_google_charts_as_image.html https://github.com/google/google-visualization-issues/issues/731