I´m in disgrace with the framework Codeigniter version 2.2.0, it only displays the json response, no errors, no chart...
Code
**Model**
function get_pata()
{
$this->db->select('theyear, cantidad_alumnos, rawkw, rawkwxgei');
$this->db->from('pdc_factor_gei');
$query = $this->db->get();
return $query->result();
}
**Controller to handle data from Model and display in view;**
function data_fik()
{
$data = $this->modelo_factor_gei->get_pata();
$category = array();
$category['name'] = 'Periodo';
$series1 = array();
$series1['name'] = 'Cantidad de Alumnos';
$series2 = array();
$series2['name'] = 'Consumo Kw por Temporada';
$series3 = array();
$series3['name'] = 'Factor GEI';
foreach ($data as $row)
{
$category['data'][] = $row->theyear;
$series1['data'][] = $row->cantidad_alumnos;
$series2['data'][] = $row->rawkw;
$series3['data'][] = $row->rawkwxgei;
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);
print json_encode($result, JSON_NUMERIC_CHECK);
$data['body'] = 'hchart_elec';
$this->load->view('main', $data);
}
**View:**
<!DOCTYPE HTML> <html> <head> Here we go <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript">
////////Graficas ////////////////////
$(document).ready(function()
{
var options =
{
chart:
{
renderTo: 'container',
type: 'column',
marginRight: 130,
marginBottom: 25
},
title:
{
text: 'KKKKSAMM',
x: -20 //center
},
subtitle:
{
text: '',
x: -20
},
xAxis:
{
categories: []
},
yAxis:
{
title:
{
text: 'LSKDLS'
},
plotLines:
[{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip:
{
formatter: function()
{
return '<b>'+ this.series.name +'</b><br/>' + this.x +': '+ this.y;
}
},
legend:
{
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("<?php echo site_url('/control_factor_gei/data_fik');?>", function(json)
{
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
chart = new Highcharts.Chart(options);
});
});
</script> </head> <body> <div id="container" style="min-width: 600px; height: 480px; margin: 0 auto"></div> </body>
**Response:**
[{"name":"Periodo","data":[2011,2012,2013,2014,2015,2016]},{"name":"Cantidad de Alumnos","data":[178745,180593,184257,188657,192176,193651]},{"name":"Consumo Kw por Temporada","data":[88972200,89414600,85017100,88017900,91786900,24221200]},{"name":"Factor GEI","data":[44503900,45485200,43248200,44220200,46609400,12318900]}]
I´m no expert in CI or php, so still learning, any help is welcome.