1

I am creating google piecharts but here I have to used iframe to show this chart, but I want to show it by ajax and without iframe.... Is there any way to show google piechart without iframe??

2 Answers 2

1

The link given by @Grrbrr404 is not working anymore so, you can try it like,

Script

<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>

Before adding above script add a div having id chart_div in you html like,

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

Show this php-example

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the google chart api to show the piechart with pure javascript.

See this page for example code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.