Highchart使用Codeigniter显示空白页

时间:2019-03-22 16:34:52

标签: highcharts codeigniter-3

作为学习高级图表的初学者,我无法找出为什么图表无法显示在视图中。我的控制器正确显示了json数据,但是当我在$ .getJSON中调用控制器以在图表中显示数据时,我得到了一个空白页。

有人可以帮助我使图表显示在视图中吗?

谢谢

我的控制器

public  function chartBarData() 
{
$query1 = $this->model_admin->getBarCha1('2019-01-24','2019-01-25');
$category = array();
$category['name'] = 'Medico';

$series1 = array();
$series1['name'] = 'Paciente';


foreach ($query1 as $row)
{
$category['data'][] = $row->Medico;
$series1['data'][] = $row->Paciente;

}

$result = array();
array_push($result,$category);
array_push($result,$series1);


print json_encode($result, JSON_NUMERIC_CHECK);
}

打印json_encode($ result,JSON_NUMERIC_CHECK)结果:

[{"name":"Medico","data":["baptiste prophete","JUAN ALBERTO SUERO","ADRIANA MATEO","RAUL ARISTY COMAS","VICTORIA LILA FRANCO","IVANHOE LINARES VENTURA"]},{"name":"Paciente","data":[2,3,15,13,1,6]}]

视图

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<script type="text/javascript">

$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'column',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Doctor patients view',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Amount'
},
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('chartBarData');?>", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
chart = new Highcharts.Chart(options);
});
});
</script>

0 个答案:

没有答案