4

我想在用户单击时突出显示(更改颜色)饼图特定切片。我可以在示例(下面的代码)中找到可以显示切片索引和确切点的信息。但是重新着色切片呢?

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();
          }
        }
      });
4

3 回答 3

2

这将做你需要的东西:

mRenderer.getSeriesRendererAt(seriesSelection.getPointIndex()).setColor(color);
mChartView.repaint();
于 2012-06-29T08:42:52.390 回答
1

图表上 onClick 的代码:

用这个:

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();
          }
        }
      });
于 2013-03-14T07:25:51.180 回答
1

您还需要确保图表是可点击的。我花了很长时间想知道为什么我不能让它工作。线

mRenderer.setClickEnabled(true);

应该包括

于 2014-07-24T23:19:29.397 回答