public Cursor ShowBarchartIncome(int yearChoose) {
Cursor cur1=db.rawQuery("SELECT "+COLEXPENSE+" as _id,"+" SUM(PRICE) as price from "+EXPENSETABLE
+" WHERE ("+YEAREX+" = "+2012+") AND ("+MONTHEX+" = 01) AND ("+TYPE+" = 'income')",new String [] {});
return cur1;
}
public class BarGraph {
public Intent getIntent(Context context) {
DBHelper.open();
int spn=editYEAR.getId();
int e = Integer.valueOf(spn);
c = DBHelper.ShowBarchartIncome(e);
startManagingCursor(c);
//data 1
int[] y ={**c.getCount()**,443,443,456,234,123,342,134,123,645,234,274};
CategorySeries series = new CategorySeries("รายรับ");
for(int i=0;i<y.length;i++){
series.add("Bar "+ (i+1),y[i]);
}
}
我无法获得真实的数据和价格,它返回1到int[] y ={c.getCount()}
如果真实数据为15000
,如何在showbarchartincome中获取数据总和价格答案 0 :(得分:2)
尝试代替new String [] {}
只使用null。
Cursor cur1=db.rawQuery("SELECT "+COLEXPENSE+" as _id,"+" SUM(PRICE) as price from "+EXPENSETABLE
+" WHERE ("+YEAREX+" = "+2012+") AND ("+MONTHEX+" = 01) AND ("+TYPE+" = 'income')", null);
<强>更新强>
要从光标获取数据,您应添加以下行:
c.moveToFirst();
price = c.getInt(c.getColumnIndex("price"));
c.getCount() just show the number of returned records.