Javascript 如何将我的json数据分配给highchart,下面是我的json数据
[{“国家”:“印度”,“年份”:1880,“人口”:2000000},{“国家”:“亚洲”,“年份”:1880,“人口”:2000000},{“国家”:“非洲”,“年份”:1880,“人口”:100000},{“国家”:“美洲”,“年份”:1880,“人口”:150000},{“国家”:“欧洲”,“年份”:1880,“人口”:1500000},{“国家”:“大洋洲”,“年份”:1880,“人口”:1200000},{“国家”:“亚洲”,“年份”:1900,“人口”:3000000},{“国家”:“非洲”,“年份”:1900,“人口”:2500000},{“国家”:“美洲”,“年份”:1900,“人口”:2304000},{“国家”:“欧洲”,“年份”:1900,“人口”:1304000},{“国家”:“大洋洲”,“年份”:1900,“人口”:2304500},{“国家”:“大洋洲”,“年份”:2013,“人口”:4000000},{“国家”:“亚洲”,“年份”:2013,“人口”:6000000},{“国家”:“非洲”,“年份”:2013,“人口”:8000000},{“国家”:“美国”,“年份”:2013,“人口”:5050000},{“国家”:“欧洲”,“年份”:2013,“人口”:6800000}] 我想知道如何将上面的json数据分配给highchart中的系列,以便动态地绘制图形 我的客户端脚本:Javascript 如何将我的json数据分配给highchart,下面是我的json数据,javascript,json,highcharts,Javascript,Json,Highcharts,[{“国家”:“印度”,“年份”:1880,“人口”:2000000},{“国家”:“亚洲”,“年份”:1880,“人口”:2000000},{“国家”:“非洲”,“年份”:1880,“人口”:100000},{“国家”:“美洲”,“年份”:1880,“人口”:150000},{“国家”:“欧洲”,“年份”:1880,“人口”:1500000},{“国家”:“大洋洲”,“年份”:1880,“人口”:1200000},{“国家”:“亚洲”,“年份”:1900,“人口”:3000000},{“国家”
<script type="text/javascript">
$(document).ready(function(){
option={
chart:{
renderTo: 'chart_div',
type: 'bar',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Continent vs. Population',
x: -20 //center
},
xAxis:{
categories:[],
},
yAxis:{
min:0,
title: {
text: 'country'
},
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: [{
data:[],
name:[]
}]
};
$.getJSON("graph.htm",function(json){
for(var count=0;count<json.length;count++){
var row=json[count];
renderData(row);
}
});
function renderData(row){
alert(row.population);
option.xAxis.categories=row.country;
option.series.data=row.population;
option.series.name = row.year;
chart = new Highcharts.Chart(option);
};
});
</script>
$(文档).ready(函数(){
选择权={
图表:{
renderTo:“图表分区”,
类型:'bar',
marginRight:130,
marginBottom:25
},
标题:{
文字:“大陆与人口”,
x:-20/中心
},
xAxis:{
类别:[],
},
亚克斯:{
分:0,,
标题:{
文字:“国家”
},
绘图线:[{
值:0,
宽度:1,
颜色:'#808080'
}]
},
工具提示:{
格式化程序:函数(){
返回“+this.series.name+”
+
this.x+':'+this.y;
}
},
图例:{
布局:“垂直”,
对齐:“右”,
垂直排列:“顶部”,
x:-10,
y:100,
边框宽度:0
},
系列:[{
数据:[],
姓名:[]
}]
};
$.getJSON(“graph.htm”,函数(json){
对于(var count=0;count请尝试以下方法:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'spline'
},
series: [{}]
};
$.getJSON('data.json', function(data) {
options.series[0].data = data;
var chart = new Highcharts.Chart(options);
});
});
稍加研究不会对您造成任何伤害:在函数(数据)中有几个数据,如国家,年份和人口,所以我需要区分和分配在一系列的数据,名称和类别。我无法绘制图表,我可以有任何后端代码的示例请。感谢评论bjb568我可以知道如何分配图表中的分类吗