I want to get data from sqlite and display it to MPAndroidChart and it show just 1 row database but have 3 BarChart. This is my code
try{
Cursor cursor = dbHelper.fetchChartStatistic("1");
cursor.moveToFirst();
int count = cursor.getCount();
String[] soal_salah = new String[count];
String[] total_nilai = new String[count];
if(cursor!=null){
do{
for(int x=0; x<count; x++) {
total_nilai[x] = cursor.getString(4);
soal_salah[x] = cursor.getString(2);
}
}while(cursor.moveToNext());
}
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < total_nilai.length; i++) {
yVals1.add(new BarEntry((float) Float.parseFloat(values[i]),i));
}
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < total_nilai.length; i++)
xVals.add(total_nilai[i%total_nilai.length]);
BarDataSet set1 = new BarDataSet(yVals1, "Data Set");
set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
set1.setDrawValues(false);
BarData data = new BarData(xVals, set1);
mChart.setData(data);
}catch(Exception c){
c.printStackTrace();
}
}
the barchart show this
Aucun commentaire:
Enregistrer un commentaire