0

i have a graph view to implement an analysis graph All the x-axis and y-axis data is get from the sqlite db data to show the output x-axis is showing date y-axis is showing weight

but I have no idea to implement them out, I am stuck, below is my code but its wrong and I haven't completed yet, can someone help me to solve and build

  DBHelperNote connect = new DBHelperNote(getActivity());
        SQLiteDatabase db = connect.getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT * FROM weight;",null);

        String[] weight = new String[cursor.getCount()];
        int i = 0;

        while(cursor.moveToNext()){
            d = cursor.getString(cursor.getColumnIndex("weightnum"));
            weight[i] = d;
            i++;
        }

        String[] date = new String[cursor.getCount()];
        int r = 0;
        while(cursor.moveToNext()){
            e = cursor.getString(cursor.getColumnIndex("date"));
            date[r] = e;
            r++;
        }

        GraphView line_graph = (GraphView) contentView.findViewById(R.id.graph);
        LineGraphSeries<DataPoint> line_series =
                new LineGraphSeries<DataPoint>(new DataPoint[] {

>> here "while" getting error

                        while ( a!=weight.length) {
                           new DataPoint(Integer.parseInt(weight[i]), Integer.parseInt(date[i]));
                            i++;
                            }

                }
        );
        line_graph.addSeries(line_series);
        line_series.setDrawDataPoints(true);
        line_series.setDataPointsRadius(10);
        line_series.setOnDataPointTapListener(new OnDataPointTapListener() {
            @Override
            public void onTap(Series series, DataPointInterface dataPoint) {
                Toast.makeText(getActivity(), "Series: On Data Point clicked: " + dataPoint, Toast.LENGTH_SHORT).show();
            }
        });
hotzst
  • 7,238
  • 9
  • 41
  • 64
Wg Sam
  • 61
  • 1
  • 2
  • 11

1 Answers1

0

Hmn, it might be an error with the data type in their example they use a double instead of an int. http://www.android-graphview.org/documentation/category/live-chart

private DataPoint[] generateData() {
        int count = 30;
        DataPoint[] values = new DataPoint[count];
        for (int i=0; i<count; i++) {
            double x = i;
            double f = mRand.nextDouble()*0.15+0.3;
            double y = Math.sin(i*f+2) + mRand.nextDouble()*0.3;
            DataPoint v = new DataPoint(x, y);
            values[i] = v;
        }
        return values;
Tripp
  • 1