Not able to set dynamic data into my pie chart, please look into my code. Hard coded code is working fine but dynamic data has an issue.
$(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]
}]
});
If instead of result1 I hard code the data then it works fine. example below
series: [{
name: 'Brands',
colorByPoint: true,
data: [{name: 'Firefox', y: 10.38 }, {name: 'Safari',y: 4.77}]
}]
Data should contain an array of objects, so instead of storing string representation of objects, write like this:
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 });
});
And then insert the array to the chart data
series: [{
name: 'Brands',
colorByPoint: true,
data: abc
}]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.