我正在使用PieChart Demo,不同之处在于片段是动态加载的,如下面的代码段所示:
public Segment[] segments;
segments = new Segment[dataList.size()];
int i=0;
for (DataList d: dadosList)
{
segments[i] = new Segment(d.name(),Float.parseFloat(d.value()));
SegmentFormatter sf1 = new SegmentFormatter(Color.parseColor(d.getColor_chart()));
sf1.getLabelPaint().setShadowLayer(3, 0, 0, Color.BLACK);
sf1.getFillPaint().setMaskFilter(emf);
pie.addSegment(segments[i],sf1);
i++;
}
pie.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
PointF click = new PointF(motionEvent.getX(), motionEvent.getY());
Log.d(TAG,"CLICK PIE CHART");
if(pie.getPie().containsPoint(click)) {
Log.d(TAG,"GET PIE");
Segment segment = pie.getRenderer(PieRenderer.class).getContainingSegment(click);
if(segment != null) {
Log.d(TAG,"SEGMENT IS NOT NULL");
final boolean isSelected = getFormatter(segment).getOffset() != 0;
deselectAll();
setSelected(segment, !isSelected);
pie.redraw();
String type = segment.getTitle();
new FetchDataListByTypeTask(type).execute();
}
}
return false;
}
但是当点击第一段时,返回空段。
这是一个Bug?或者我做错了什么?
更新
当段大于饼图的50%时,会出现此错误。
答案 0 :(得分:1)
这已在Androidplot 1.5.1中修复。