谷歌饼图使用php, mysql和jquery ajax


Google pie chart using php, mysql and jquery ajax

我正在创建google piecharts,但这里我必须使用iframe来显示这个图表,但我想显示它的ajax和没有iframe....有没有办法显示谷歌piechart没有iframe??

@Grrbrr404给出的链接不再工作了,所以,你可以试试,

脚本

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
  var jsonData = $.ajax({
      url: "getData.php",
      dataType:"json",
      async: false
      }).responseText;
  // Create our data table out of JSON data loaded from server.
  var data = new google.visualization.DataTable(jsonData);
  // Instantiate and draw our chart, passing in some options.
  var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  chart.draw(data, {width: 400, height: 240});
}
</script>

在添加上述脚本之前,在html中添加id为chart_div的div,如

<div id="chart_div"></div>
php-example

您可以使用google chart api来显示纯javascript的piechart。