0

I have my method to retrieve data from sqlite data using rawQuery. But now I don't know how to put it in the graph view,( for ex: all date and all weight column) put in the graphview

Here is the code to retrieve data

DBHelperNote connect = new DBHelperNote(AnalysisGraph.this);
SQLiteDatabase db = connect.getReadableDatabase();

Cursor cursor = db.rawQuery("SELECT * FROM weight;", null);

if (cursor.moveToNext()) {
    d = cursor.getString(cursor.getColumnIndex("date"));
    e = cursor.getString(cursor.getColumnIndex("weight"));

    tv.setText(d);
    tc.setText(d);
}

db.close();

and this is my graphview , and how can i use the retrieve data method that I have and add or combine the data to implement in my graphview ?

 GraphView line_graph = (GraphView) contentView.findViewById(R.id.graph);
 LineGraphSeries<DataPoint> line_series =
                new LineGraphSeries<DataPoint>(new DataPoint[] {
                        new DataPoint(0, 1),
                        new DataPoint(1, 5),
                        new DataPoint(2, 3),
                        new DataPoint(3, 2),
                        new DataPoint(4, 6)
                });
 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();
            }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Wg Sam
  • 61
  • 1
  • 2
  • 11

1 Answers1

0

You just make a one data model of your column list what you need and then store a data into that datamodel. So you can easily find a gap in that.

package yourpakage name;

public class datamodel {
private String id, weight, time, date;

public datamodel(String id, String weight, String time, String date) {
    this.id = id;
    this.weight = weight;
    this.time = time;
    this.date = date;

}

public String getId() {
    return this.id;
}

public String getweight() {
    return this.weight;
}


public String getTime() {
    return this.time;
}

public String getDate() {
    return this.date;
}

public void setid(String id) {
    this.id = id;
}

public void setweight(String weight) {
    this.weight = weight;
}


public void setTime(String time) {
    this.time = time;
}

public void setDate(String date) {
    this.date = date;
}

This a datamodel for your example.and than store your data into that like that. You make one array list file in main Arraylist<datamodel> your filename (file).

    DBHelperNote connect = new DBHelperNote(AnalysisGraph.this);
    file = new Arraylist<>;
    SQLiteDatabase db = connect.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM weight;", null);

    if (cursor.moveToNext()) {
         file.add(new datamodel(data.getString(data.getColumnIndex("id")), data.getString(data.getColumnIndex("weight")),
                   , data.getString(data.getColumnIndex("time")),
                    data.getString(data.getColumnIndex("date"))));
    }

    db.close();

Now your data was store into datamodel then you just retrieve data from it.and display into graph easily you don't need to make an arraylist.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kishan patel
  • 214
  • 1
  • 12
  • I mean i have my data in my sqlite db aldy, and i hv my method to retrieve and read data out , now point is how can i put the data tht is get and add and combine in the graphview cause i need to something like analysis result graph – Wg Sam Jan 22 '16 at 05:29
  • u can use any library to display a grap ? – Kishan patel Jan 22 '16 at 05:32
  • if u can't just use mpandroidchart libaray it can be sutiable for that what u want . and esaly implement.for your graphview .https://github.com/PhilJay/MPAndroidChart – Kishan patel Jan 22 '16 at 05:35
  • I have the graphview code and retrieve data code, but now i dunno how to implement my data to the graphview and the link you send me is confuse, did you can use my code to modify it ? – Wg Sam Jan 22 '16 at 05:59
  • i have make same app using that library just refer that library u have easliy impelement .i try to change your code.see example of mpandroidchart in google. u have some idea how can implement that library – Kishan patel Jan 22 '16 at 06:08
  • take a look aldy but dunno how to change my to that .? can help me change my code or guild – Wg Sam Jan 22 '16 at 06:36
  • can i know u have use any library ? – Kishan patel Jan 22 '16 at 07:24
  • com.jjoe64.graphview.GraphView – Wg Sam Jan 22 '16 at 07:34
  • u can use mpandroidchart library it is batter for you .beacuse u can esaylly impement what u want https://www.numetriclabz.com/android-line-chart-using-mpandroidchart-tutorial/ here is link for tutorial of mpandroidchart library .try this thank you – Kishan patel Jan 22 '16 at 08:46
  • but how can i put my data inside graphview seen the data in sqlite is real time update – Wg Sam Jan 24 '16 at 15:59