I am trying to use google charts to display some data that is retrieved from a mysql query. This is project is being done in codeigniter. I would like to know how I can display the number that my query is returning. My code is as follows:
Controller:
<?php
class RevProgressC extends CI_Controller
{
public function index()
{
$this->load->model('PaperM');
$this->load->model('AddRevM');
$data['rowa']=$this->PaperM->ViewReviewed();
$this->load->view('RevProgress',$data);
}
}
?>
Model:
function ViewReviewed()
{
$this->db->where('status','1');
$this->db->or_where('status','2');
$this->db->from('assign');
$data = $this->db->count_all_results();
return $data;
}
View:
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<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.
//<?php $this->load->model('PaperM');
//$data['rowa']=$this->PaperM->ViewReviewed();
//?>
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Reviewed', 5],
['Pending Review', 10]
]);
//var data = google.visualization.arrayToDataTable(raw_data);
// Set chart options
var options = {'title':'Reviewed and Not Reviewed Papers',
is3D: true,};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
Instead of the 5 and 10, I would like to use a php variable that will be holding a value from the above mentioned function. Then pass it onto the script. Any help would be appreciated.
Change these line..
On Controller
$this->load->view('RevProgress',$data);
To
$this->load->view('RevProgress',json_encode($data));
** AND On view PAge**
data.addRows([ ['Reviewed', 5], ['Pending Review', 10] ]);
To
data.addRows(<?php echo $RevProgress;?>);