我已经阅读了很多帖子,但似乎没有一个帖子可以解决我的问题。
我正在尝试完成一个在图表中显示数据的脚本(HighCharts)。
一切正常,但我想用从MySQL数据表中提取的数据填充类别。到目前为止,我已经提取了图表的数据,但没有提取类别。我不知道如何让AName(我的类别)显示在[]类别中。
任何人都可以提前帮助,非常感谢。
我的查询脚本重新调整: [{"名称":" AName""数据":["阿斯塔纳""印度"&# 34; Arik"," Asiana","英国","太平洋","埃及"," Ethio&# 34;,"阿提哈德""海湾""韩国""科威特""文莱"&# 34; SriLan"]}, {"名称":"星期六""数据":[93.8,86.4,85.4,83.9,84.3,84.2,89.4,88.9,80.5,83.8,82.7 ,80.6,83.8,80.2]}]
生成图表的脚本:
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("charts_get_data.php", function(json) {
$('#container1').highcharts({
chart: {
renderTo: 'container',
type: 'column',
marginRight: 30,
marginBottom: 110
},
title: {
text: ' Crew Feedback Overall Satisfaction %',
x: -20, //center
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '11px'
}
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: [],
labels: {
style: {
color: '#F00',
font: '11px Tahoma, Verdana, sans-serif'
}
}
},
yAxis: {
max:100,
showFirstLabel: false,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:2,
gridLineColor:'#ddd',
title: {
text: 'Percentage',
style: {
fontFamily: 'Tahoma',
color: '#000000',
fontWeight: 'bold',
fontSize: '11px'
}
},
plotLines: [{
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
enabled: false
},
series: json
});
});
});
});
答案 0 :(得分:0)
更新如果您可以获得所需格式的json响应,例如下面的json,您可以遍历多个名称/系列,但类别必须是项目数组而不是列表。在This fiddle link
更新了这个回复的小提琴 {"name":"AName","Categories": ["Astana","India","Arik","Asiana","British","Pacific","Egypt","Ethio ","Etihad","Gulf","Korean","Kuwait","Brunei","SriLan"],"data": [93.8,86.4,85.4,83.9,84.3,84.2,89.4,88.9,80.5,83.8,82.7,80.6,83.8,80.2]}
如果您不想更改json的输出
,请使用以下代码 var categories=[];
var data2 =[];
var abc =[{"name":"AName","data":["Astana","India","Arik","Asiana","British","Pacific","Egypt","Ethio ","Etihad","Gulf","Korean","Kuwait","Brunei","SriLan"]},{"name":"Sat","data": [93.8,86.4,85.4,83.9,84.3,84.2,89.4,88.9,80.5,83.8,82.7,80.6,83.8,80.2]}];
$.each(abc,function(i,el)
{ if (el.name=="AName")
categories = el.data;
else
data2.push(el);
});