我希望在用户点击时突出显示(更改颜色)饼图特定切片。 我可以在样本(下面的代码)中找到可以显示切片的索引和确切的点。但是重新着色切片呢?
mChartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast
.makeText(PieChartBuilder.this, "No chart element was clicked", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
PieChartBuilder.this,
"Chart element data point index " + seriesSelection.getPointIndex()
+ " was clicked" + " point value=" + seriesSelection.getValue(),
Toast.LENGTH_SHORT).show();
}
}
});
答案 0 :(得分:2)
这将完成你需要的东西:
mRenderer.getSeriesRendererAt(seriesSelection.getPointIndex()).setColor(color);
mChartView.repaint();
答案 1 :(得分:1)
点击图表上的代码:
使用此:
mChartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(PieChartBuilder.this, "No chart element selected", Toast.LENGTH_SHORT)
.show();
} else {
for (int i = 0; i < mSeries.getItemCount(); i++) {
mRenderer.getSeriesRendererAt(i).setHighlighted(i == seriesSelection.getPointIndex());
}
mChartView.repaint();
Toast.makeText(
PieChartBuilder.this,
"Chart data point index " + seriesSelection.getPointIndex() + " selected"
+ " point value=" + seriesSelection.getValue(), Toast.LENGTH_SHORT).show();
}
}
});
答案 2 :(得分:1)
您还需要确保图表可以点击。我花了很长时间想知道为什么我无法让它工作。这条线
mRenderer.setClickEnabled(true);
应该包括