[英]Unable to get dynamic data into Jquery pie chart
無法將動態數據設置到我的餅圖中,請查看我的代碼。 硬編碼代碼可以正常工作,但動態數據存在問題。
$(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}]
}]
數據應包含一個對象數組,因此與其存儲對象的字符串表示形式,不如這樣寫:
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
}]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.