Php Highchart不工作(Codeigniter-JSON-Bootstrap)
我的海图有个问题,就是我的海图没有出现。我使用Codeigniter并将数据(从表)转换为JSON。我希望显示基于日期的Php Highchart不工作(Codeigniter-JSON-Bootstrap),php,json,twitter-bootstrap,codeigniter,highcharts,Php,Json,Twitter Bootstrap,Codeigniter,Highcharts,我的海图有个问题,就是我的海图没有出现。我使用Codeigniter并将数据(从表)转换为JSON。我希望显示基于日期的人口和金额 以下是我的JSON数据: [{ "name":"Date", "data":["27-OCT-14","28-OCT-14","29-OCT-14","30-OCT-14","31-OCT-14","01-NOV-14","02-NOV-14"] }, { "name":"Population", "data":[6171,6990,6882,6
人口
和金额
以下是我的JSON数据:
[{
"name":"Date",
"data":["27-OCT-14","28-OCT-14","29-OCT-14","30-OCT-14","31-OCT-14","01-NOV-14","02-NOV-14"]
},
{
"name":"Population",
"data":[6171,6990,6882,6889,6860,7619,6698]
},
{"name":"Amount",
"data":[361154716.01,409210099.77,407191552.71,416366585.57,418588842.18,435168113.68,402163667.57]
}]
这是我用来对json编码的控制器
function daily(){
$data=array(
'title'=>'SOA_OTC - Daily',
'=>$this->model_app->get_Soa_Daily()
);
$category = array();
$category['name'] = 'Date';
$series1 = array();
$series1['name'] = 'Population';
$series2 = array();
$series2['name'] = 'Amount';
foreach($data['day']['START_EXECUTION'] as $row){
$category['data'][] = $row;
}
foreach($data['day']['NUM_OF_POPULATION'] as $row){
$series1['data'][] = $row;
}
foreach($data['day']['SUM_AMOUNT'] as $row){
$series2['data'][] = $row;
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
print json_encode($result, JSON_NUMERIC_CHECK);
$this->load->view('element/v_header',$data);
$this->load->view('pages/v_soaotc_daily');
$this->load->view('element/v_footer');
}
这是我在视图中的Highchart脚本:
script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'containers',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Project Requests',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Requests'
},
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('daily', function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
var chart = new Highcharts.Chart(options);
});
});
</script>
<div id="containers" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
scripttype=“text/javascript”>
$(文档).ready(函数(){
变量选项={
图表:{
renderTo:'容器',
键入:“行”,
marginRight:130,
marginBottom:25
},
标题:{
文本:“项目请求”,
x:-20/中心
},
副标题:{
文本:“”,
x:-20
},
xAxis:{
类别:[]
},
亚克斯:{
标题:{
文本:“请求”
},
绘图线:[{
值:0,
宽度:1,
颜色:'#808080'
}]
},
工具提示:{
格式化程序:函数(){
返回“+this.series.name+”
+
this.x+':'+this.y;
}
},
图例:{
布局:“垂直”,
对齐:“右”,
垂直排列:“顶部”,
x:-10,
y:100,
边框宽度:0
},
系列:[]
}
$.getJSON('daily',函数(json){
options.xAxis.categories=json[0]['data'];
options.series[0]=json[1];
options.series[1]=json[2];
var图表=新的Highcharts.图表(选项);
});
});
我的代码有问题吗?非常感谢你的帮助。
谢谢
选项。series
是一个空数组,您必须将其推入:
$.getJSON('daily', function(json) {
options.xAxis.categories = json[0]['data'];
options.series.push(json[1]);
options.series.push(json[2]);
var chart = new Highcharts.Chart(options);
});
控制台是否正在抛出错误?您是否验证了php正在生成所需的数据结构?@Rooster控制台中未发现错误。对于php验证,请查看我的控制器,我打印json_编码以查看我的数据结构的结果,我得到的与上面显示的相同(我的json数据)。请告诉我此“$row”变量是否包含字符串:“[6171699068826889686076196698]”或它是数组?因为问题似乎在于打字。你有现场演示吗?