vendredi 26 juin 2015

error with draw mpchart using sqlite dataset

i use mpchart to draw chart for my sqlite database, but it runs with crash, this is eclipse error log : (before crash, LogCat shows dataset)

one or more of the Dataset Entry array longer than the x-values array of this CharData object

this is my "onProgressChanged" method code,that i think caused problem:

   public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        tvX.setText("" + (mSeekBarX.getProgress() + 1));
        tvY.setText("" + (mSeekBarY.getProgress()));
        ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
        TimeListDatabaseHelper db = new TimeListDatabaseHelper(this);
        for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
            Cursor c = db.getTimeRecordList();
            if (c != null && c.getCount() > 0) { 
                c.moveToFirst();
                for (int count = 0; count < c.getCount(); count++) {
                   yVals3.add(new BarEntry(c.getInt(0), count));
                   c.moveToNext();

                }
                         }
            c.close();
        for (Object obj1: yVals3) {
            Log.i("mSeekBarX1", obj1.toString());
        }
      }

        ArrayList<String> xVals = new ArrayList<String>();
        for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
          xVals.add((int) yVals3.get(i).getVal() + "");
              }
         BarDataSet set1 = new BarDataSet(yVals3, "Data Set");
        set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set1.setDrawValues(false);

        ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
        dataSets.add(set1);

        BarData data = new BarData(xVals, dataSets);

        mChart.setData(data);
        mChart.invalidate();
    }

Aucun commentaire:

Enregistrer un commentaire