so i started creating this chartjs to be connected in database i have used this because of course ChartJS is a live open source chart..i download the offline jqueryJS and ChartJS and it did work so i knew that there is nothing wrong with my script now when i tried to connect it to the database it wont show some result/chart, status code is 200 OK but there is no data in my properties using the developer tool, here is my code. Please explain why it didn't work. Thank you big help.
i have my uri where monthlyReport views the page and / 2 is my Project_No
http://localhost/****/index.php/Main/monthlyReport/2
offline downloadable script is working on non database query
<script src="<?php echo base_url('assets/jquery/jquery.min.js')?>"></script>
<script src="<?php echo base_url('assets/js/Chart.js')?>"></script>
button and canvas where it will fire the post script and views my chart
<input type="button" id="btnchart" value="Chart">
<canvas id="myChart" width="400" height="218"></canvas>
script to be fired
<script type="text/javascript">
var paramMonth = [];
var paramPercentage = [];
$('#btnchart').click(function(){
$.post("<?php echo site_url('Main/chartData'); ?>",
function(data) {
var obj = JSON.parse(data);
$.each(obj,function(i,item) {
paramMonth.push(item.Month);
paramPercentage.push(item.Completion_Percentage);
});
var ctx = $('#myChart');
var myChart = new Chart(ctx, {
type: 'horizontalBar',
data: {
labels: paramMonth,
datasets: [{
label: paramYear,
backgroundColor: 'rgb(3, 0, 102)',
borderColor: 'rgb(3, 0, 102)',
data: paramPercentage,
},{
label: paramYear,
backgroundColor: 'rgb(255, 0, 0)',
borderColor: 'rgb(255, 0, 0)',
data: paramPercentage,
},{
type: 'line',
label: "Line Graph",
data: paramPercentage,
}],
},
// Configuration options go here
options: {}
});
});
});
</script>
controller gets the uri, query the model and converts the data to json
public function chartData()
{
$data['p_id'] = $this->uri->segment(3);
$result = $this->foo_pro->getChartData('p_id');
echo json_encode($result);
}
query the monthly reports Month and Completion_Percentage where Project_No = 2
public function getChartData()
{
$this->db->select('*');
$this->db->from('monthlyreport');
$this->db->where('Project_No', $this->uri->segment(3));
$query = $this->db->get();
return $query->result();
}
so this here is my work update.. if no where clause
$this->db->where('Project_No', $this->uri->segment(3));
these what happens when i add where clause. no data will be shown.

