Here is my code...
<?php
$survey_question = "SELECT id,answer,total_attempt,questionid from survey_answer where `questionid` = $ques_id AND `answer`!='' AND status='1' ORDER BY id ASC";
$answers_result = @mysql_query($survey_question);
$table = array();
$table['cols'] = array(
array('label' => 'Question', 'type' => 'string'),
array('label' => 'Total Attempt', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($answers_result)) {
//print_r($r);
$temp = array();
$temp[] = array('v' => (string) $r['answer']); // you will probably need to transform this into the Date object format
$temp[] = array('v' => (int) $r['total_attempt']); // typecast to int, float, whatever - if you don't, it will be interpreted as a string
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonData = json_encode($table);
//echo $jsonData;
?>
<div id="draw_chart<?php echo $questio_print ?>"></div>
<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() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?php echo $jsonData ?>);
var options = {
is3D: true,
width: 900,
height: 300
};
// Instantiate and draw our chart, passing in some options.
// Do not forget to check your div ID
var chart = new google.visualization.PieChart(document.getElementById('draw_chart<?php echo $questio_print ?>'));
chart.draw(data, options);
}
</script>