<?php
$con = mysqli_connect('localhost','root','','cash');
$query = "SELECT SUM(amount) AS amount, category FROM cash GROUP BY
category";
$exec = mysqli_query($con,$query);
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'category', 'type' => 'string'),
array('label' => 'amount', 'type' => 'number')
);
$rows = array();
while($r = mysqli_fetch_assoc($exec)) {
$temp = array();
$temp[] = array('v' => (string) $r['category']);
$temp[] = array('v' => (int) $r['amount']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
?>
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"
></script>
<script type="text/javascript" src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(<?=$jsonTable
?>);
var options = {
title: ' Budget Breakdown ',
is3D: 'true',
width: 800,
height: 600
};
var chart = new google.visualization.PieChart(document.
getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--this is the div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
On this page I want to insert a Google Chart Table using the same table but
the query being "SELECT amount, category, transDate FROM cash GROUP By uID"
Here's the JSON of my MySQL table
[{"TransactionID":"1","category":"Food","amount":"200","transDate":
"2016-03-02","uID":"1"}, {"TransactionID":"2","category":"Bills","amount":
"3500","transDate":"2016-03-05","uID":"1"}, {"TransactionID":"3","category":
"School","amount":"5000","transDate":"2016-03-08","uID":"2"}, {
"TransactionID":"4","category":"Recreation","amount":"500","transDate":
"2016-03-10","uID":"1"}, {"TransactionID":"5","category":"Bills","amount":
"200","transDate":"2016-03-13","uID":"3"}]
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/9cbb1cd2-8685-4078-a546-b8fd41c14ee2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.