2012-06-20 78 views
4

我想在用戶點擊時突出顯示餅圖特定切片(更改顏色)。 我可以在樣本(下面的代碼)中找到它可以顯示切片的索引和確切點。但是如何重新着色切片呢?在AChartEngine中單擊時突出顯示餅圖切片

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

回答

2

這也將這樣做的東西,你需要:

mRenderer.getSeriesRendererAt(seriesSelection.getPointIndex()).setColor(color); 
mChartView.repaint(); 
+0

地方,所以我們需要添加呢? – Goofy

+1

旁邊的問題中的代碼。請參閱:http://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/PieChartBuilder.java –

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

你還需要確保圖表是可點擊的。我花了很長時間想知道爲什麼我不能使用它。行

mRenderer.setClickEnabled(true); 

應包括

相關問題