您好,我想显示带有从数据库中获取的数据的饼图,但我只能看到一个结果而不是全部。我不明白错误在哪里。谢谢你的帮助。
String sql = ......;
Cursor c = db.rawQuery(sql, null);
int count = c.getCount();
double[] values = new double[count];
String[] categoryNames = new String[count];
int[] colori = new int [count];
for(int m=0; m<count; m++) {
c.moveToNext();
categoryNames[m] = c.getString(0);
values[m] = c.getDouble(1);
colori[m] = c.getInt(2);
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < categoryNames.length; i++) {
yVals1.add(new Entry(m, m, (double) (values[i])));
}
ArrayList<String> xVals = new ArrayList<String>();//array legend
for (int i = 0; i < categoryNames.length; i++)
xVals.add(categoryNames[m % categoryNames.length]);
PieDataSet set1 = new PieDataSet(yVals1, "Election Results");
set1.setSliceSpace(3f);
set1.setColors(ColorTemplate.createColors(colori));
PieData data = new PieData(xVals,set1);
mChart.setData(data);
// undo all highlights
mChart.highlightValues(null);
mChart.invalidate();
}
c.close();
db.close();
}
EDIT---------------------------- 我几乎解决了,但不管数据如何,我总是得到等份的图表。例如我有这些百分比:
Category1 (15,4), Category2(30,8), Category3(53,8)
这是图表,帮我找出错误?谢谢