这是我的JSON格式数据。这里,country_Name应该在y轴上,值应该在x轴上显示。我在最近2天搜索这个答案,但是我无法在Highcharts中加载外部JSON数据来显示条形图。我需要动态条形图,而更改我的JSON数据会自动更改我的条形图。我完成了以下代码,但它只显示标题,副标题和y轴文本,但没有显示条形图。编码如下所示。
[
{
"Country_Name": "MYANMAR",
"value": [
143
]
},
{
"Country_Name": "MONGOLIA",
"value": [
46
]
},
{
"Country_Name": "ZIMBABWE",
"value": [
1
]
},
{
"Country_Name": "Bahrain",
"value": [
1
]
}
]
$.getJSON('recipient_country.json', function(data) {
console.log(data);
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: 'Recipient Country'
},
subtitle: {
text: 'Source: aidstream.org'
},
xAxis: {
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Country Name',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return ''+
this.series.Country_Name +': '+ this.y +' activities';
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -100,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: data
});
});
});