无法将动态数据设置到我的饼图中,请查看我的代码。硬编码的代码工作正常,但动态数据存在问题。
$(contact_listddd).each(function(index, data) {
total_kra=data.graph_count;
kra_type=data.kra_type;
abc+= '{name: "'+kra_type+'",y: '+total_kra+'},';
});
var result1 = abc.substring(0, abc.length-1);
$('#container2').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares January, 2015 to May, 2015'
},
tooltip: {`enter code here`
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [result1]
}]
});
如果不是result1而是硬编码数据,那么它可以正常工作。以下示例
series: [{
name: 'Brands',
colorByPoint: true,
data: [{name: 'Firefox', y: 10.38 }, {name: 'Safari',y: 4.77}]
}]
答案 0 :(得分:0)
数据应该包含一个对象数组,所以不要存储对象的字符串表示,而是这样写:
var abc = [];
$(contact_listddd).each(function(index, data) {
total_kra=data.graph_count;
kra_type=data.kra_type;
abc.push({ name: kra_type, y: total_kra });
});
然后将数组插入图表数据
series: [{
name: 'Brands',
colorByPoint: true,
data: abc
}]