setData method
Implementation
@override
setData(List<PieChartItem> items) {
items.sort((a, b) => -a.weight.compareTo(b.weight));
totalWeight = items.map((item) => item.weight).reduce((a, b) => a + b);
if (items.length > maxLabels) {
var lefts = items.sublist(maxLabels - 1);
items = items.sublist(0, maxLabels - 1);
var leftWeight = lefts.map((i) => i.weight).reduce((a, b) => a + b);
items.add(PieChartItem('other..', leftWeight)
..description = lefts.map((i) => '${(100 * i.weight / totalWeight).toStringAsFixed(2)}% ${i.label}').join('<br/>'));
}
var c = 0;
for (var i = 0; i < items.length; i++) {
if (i == items.length - 1 && c == 0) {
//make sure last color is different than first
c = 1;
}
items[i].color = _colors[c];
c++;
if (c >= _colors.length) {
c = 0;
}
}
super.setData(items);
}