我使用这种方法将谷歌图表保存为图像,使用base64 url从服务器端保存在某个文件夹中,最后在fpdf中作为文件夹中的图像使用。
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['', ''],
['Numerical', 4],
['Verbal', 6],
['Mechanical', 4],
['Reasoning', 5],
['Spatial', 9]
]);
var options = {
title : '',
vAxis: {title: "", viewWindowMode:'explicit',
viewWindow:{
max:12,
min:0
}},
hAxis: {title: ""},
seriesType: "bars",
series: {5: {type: "line"}}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
var app1=(chart.getImageURI());
$.post("appt1.php",{postapp: app1},
function(){});
}
</script>
<div id="chart_div" style="display: none;"></div>
<!-- On the Server side do this to store image appt1.php -->
$data =$_POST['postapp'];
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('exam_images/'."1".'.png', $data);