您正在尝试使用Android中的achartengine库开发圆环图。我的要求是,当我点击甜甜圈图表的任何部分时,我需要突出显示并在中心显示相应的标签。 但是当我使用onclick / ontouch监听器时,无论是否单击它返回null。
mChartView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v == mChartView2){
Log.i("view", ""+((GraphicalView) v).getCurrentSeriesAndPoint());
}
Log.i("dfg", ""+((GraphicalView) v).getCurrentSeriesAndPoint());
SeriesSelection seriesSelection = ((GraphicalView) v).getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(context1, "No chart element selected", Toast.LENGTH_SHORT)
.show();
}else {
for (int i = 0; i < categorySeries.getCategoriesCount(); i++) {
renderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
}
mChartView2.repaint();
Toast.makeText(
context1,
"Chart data point index " + seriesSelection.getPointIndex() + " selected"
+ " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}
}
});