I have following code
$objDbResultByModel = $objDatabase->Query($modelQuery);
$return_arr = array();
echo "<h3>Total Model No<br></h3><strong>";
while ($mixRow = $objDbResultByModel->FetchArray()) {
$row_array['Model'] = $mixRow['Manu']." - " .$mixRow['model'];
$row_array['Quantity'] = $mixRow['total'];
array_push($return_arr,$row_array);
$jsonTable = json_encode($return_arr);
echo $jsonTable;
I get following results in my browser.
[
{"Model No.":"HP - 3120-MT","Quantity":"1"},
{"Model No.":"IBM - 6087-CN8","Quantity":"1"},
{"Model No.":"Fujitsu - D2594","Quantity":"4"},
{"Model No.":"Fujitsu - D2750","Quantity":"15"},
{"Model No.":"HP - DC 7800","Quantity":"43"},
{"Model No.":"HP - DC7700","Quantity":"1"},
{"Model No.":"HP - DC7900","Quantity":"8"},
{"Model No.":"Fujitsu - E5720","Quantity":"1"},
{"Model No.":"RM - RM","Quantity":"5"},
{"Model No.":"HP - XW4400","Quantity":"1"},
{"Model No.":"HP - XW4600","Quantity":"2"}
]
But if I use jsonTable with google charts api it does not work. What I am doing wrong? See below.
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Model');
data.addColumn('number', 'Quantity');
data.addRows([
<?php echo $jsonTable; ?>
]);
// Set chart options
var options = {'title':'Model Quantity in this Shipment',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
Can you please help me with what the problem is here?
data.addRows([{'Model':'abc','Quantity':10}]);
If so, we know the error is in your datatables – Jacob Raccuia Jul 24 '14 at 13:27