我想要显示饼图。为此,我有以下代码:
public class Piechart extends Activity
{
GraphicalView mChartView = null;
private DefaultRenderer mRenderer = new DefaultRenderer();
private CategorySeries mSeries = new CategorySeries("Expenses");
private static int[] COLORS = new int[]{ Color.GREEN, Color.BLUE, Color.MAGENTA, Color.YELLOW, Color.RED, Color.DKGRAY, Color.BLACK};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Cursor cursor;
int count = cursor.getCount();
double[] values = new double[count];
String[] categoryNames = new String[count];
for(int i = 0; i < count; i++)
{
cursor.moveToNext();
values[i] = cursor.getDouble(1);
categoryNames[i] = cursor.getString(0);
}
int i = 0;
mSeries.add(categoryNames[i], values[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
renderer.setDisplayChartValues(true);
mRenderer.addSeriesRenderer(renderer);
i++;
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
mChartView.setLayoutParams(params);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.chartsRelativeLayout);
layout.addView(mChartView);
}
但是在下面的代码中我有一个错误。错误是“方法setDisplayChartValues(boolean)未定义类型SimpleSeriesRenderer”。
renderer.setDisplayChartValues(true);
我正在关注此链接中的教程。 http://mukeshsoni.wordpress.com/2012/09/18/how-to-setup-achartengine-within-an-activity/
你能帮帮我吗?