我使用 AchartEngine 制作一個 pie chart,如下:
Pie Chart 圖像
我給所有的顏色部分都添加了onclick事件,但是有時候綠色部分不能點擊。
mChartView = ChartFactory.getPieChartView(this, adc.buildCategoryDataset("Project budget", values), renderer);
mChartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast
.makeText(GeneratedChartDemo.this, "No chart element was clicked", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
GeneratedChartDemo.this,
"Chart element data point index " + seriesSelection.getPointIndex()
+ " was clicked" + " point value=" + seriesSelection.getValue(),
Toast.LENGTH_SHORT).show();
}
}
});
哪裡出錯或者是丟失什麼呢?
添加一個selectable buffer?
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);