データベースから複数のデータセットを取得するグラフを作成しましたが、グラフには表示されず、利用可能なデータのみが表示されます。誰でも問題を指摘できますか?mpandroidchart チュートリアルを読んでみましたが、まだ問題を指摘できません。前もって感謝します
public ArrayList<String> queryXData(){
ArrayList<String> xNewData = new ArrayList<String>();
String query = "SELECT Subject FROM gradesinfo ORDER BY Subject";
Cursor cursor = cn.rawQuery(query, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
xNewData.add(cursor.getString(cursor.getColumnIndex("Subject")));
}
cursor.close();
return xNewData;
}
public ArrayList<Float> queryYData(){
ArrayList<Float> yNewData = new ArrayList<Float>();
String query = "SELECT PG FROM gradesinfo ORDER BY Subject";
Cursor cursor = cn.rawQuery(query, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
yNewData.add(cursor.getFloat(cursor.getColumnIndex("PG")));
}
cursor.close();
return yNewData;
}
public ArrayList<Float> queryYData2(){
ArrayList<Float> yNewData2 = new ArrayList<Float>();
String query = "SELECT MG FROM gradesinfo ORDER BY Subject";
Cursor cursor = cn.rawQuery(query, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
yNewData2.add(cursor.getFloat(cursor.getColumnIndex("MG")));
}
cursor.close();
return yNewData2;
}
public ArrayList<Float> queryYData3(){
ArrayList<Float> yNewData3 = new ArrayList<Float>();
String query = "SELECT FG FROM gradesinfo ORDER BY Subject";
Cursor cursor = cn.rawQuery(query, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
yNewData3.add(cursor.getFloat(cursor.getColumnIndex("FG")));
}
cursor.close();
return yNewData3;
}
private void addData(){
Cursor cursor = cn.rawQuery("SELECT PG, MG, FG FROM gradesinfo ORDER BY Subject", null);
if(cursor.getCount()>=2){
ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
for (int i = 0; i < queryYData().size(); i++)
yVals.add(new BarEntry(queryYData().get(i), i));
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < queryYData2().size(); i++)
yVals1.add(new BarEntry(queryYData2().get(i), i));
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
for (int i = 0; i < queryYData3().size(); i++)
yVals2.add(new BarEntry(queryYData3().get(i), i));
ArrayList<String> xVals = new ArrayList<String>();
for(int i = 0; i < queryXData().size(); i++)
xVals.add(queryXData().get(i));
BarDataSet dataSet = new BarDataSet(yVals, "Prelim");
dataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet dataSet2 = new BarDataSet(yVals1, "Midterm");
dataSet2.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet dataSet3 = new BarDataSet(yVals2, "Finals");
dataSet3.setColors(ColorTemplate.COLORFUL_COLORS);
ArrayList<BarDataSet> dataset = new ArrayList<BarDataSet>();
dataset.add(dataSet);
dataset.add(dataSet2);
dataset.add(dataSet3);
BarData data = new BarData(xVals, dataset);
LimitLine line = new LimitLine(75f, "Passing Grade");
line.setTextSize(8f);
line.setLineWidth(4f);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.addLimitLine(line);
barChart.setData(data);
barChart.setDescription("Grades Chart");
barChart.animateY(2000);
}