问题
I want to group data thar have under 10% percentage to be grouped to slice of pie named others. Is it possible? Pie-chart
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2]
]
}]
回答1:
You just need to calculate slightly different data. Iterate over the entries looking for items with < 10%. Add these to an 'other' category.
Something like this:
var data = [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2]
];
var newData=[];
var other=0.0;
for (var slice in data) {
if (data[slice][1] < 10) {
other += data[slice][1];
} else {
newData.push(data[slice]);
}
}
newData.push(['other',other]);
http://jsfiddle.net/q25u2hyr/
来源:https://stackoverflow.com/questions/28883606/group-smaller-slices-in-pie-charts-to-improve-readability