retrieve data from database and show them in bar chart using MPAndroidChart in android -


i know how show raw data in bar chart using mpandroidchart got problem in real scenario. have data in sqlite database , want show them in bar chart. please give me reference or simple example.

database table has 2 columns month , numbers. eg: jan = 200, feb = 300, etc.

i have searched many not find right one. either 2-3 years old or not type mentioned.

thanks in advance.

here answer question. these 2 methods store x-axis data , y-axis data in arrays.

public arraylist<string> queryxdata(){     arraylist<string> xnewdata = new arraylist<string>();     string query = "select " + daily_date + " " + table_daily_frag;     cursor cursor = msqlitedatabase.rawquery(query, null);     (cursor.movetofirst(); !cursor.isafterlast(); cursor.movetonext()) {         xnewdata.add(cursor.getstring(cursor.getcolumnindex(daily_date)));     }     cursor.close();     return xnewdata; }  public arraylist<float> queryydata(){     arraylist<float> ynewdata = new arraylist<float>();     string query = "select " + daily_total + " " + table_daily_frag;     cursor cursor = msqlitedatabase.rawquery(query, null);     (cursor.movetofirst(); !cursor.isafterlast(); cursor.movetonext()) {         ynewdata.add(cursor.getfloat(cursor.getcolumnindex(daily_total)));     }     cursor.close();     return ynewdata; } 

this method show barchart. call method in activity.

private void adddata(){      arraylist<barentry> yvals = new arraylist<barentry>();      (int = 0; < mexpensedb.queryydata().size(); i++)         yvals.add(new barentry(mexpensedb.queryydata().get(i), i));      arraylist<string> xvals = new arraylist<string>();     for(int = 0; < mexpensedb.queryxdata().size(); i++)         xvals.add(mexpensedb.queryxdata().get(i));      bardataset dataset = new bardataset(yvals, "expense values");     dataset.setcolors(colortemplate.colorful_colors);      bardata data = new bardata(xvals, dataset);       limitline line = new limitline(12f, "average daily expense");     line.settextsize(12f);     line.setlinewidth(4f);     yaxis leftaxis = barchart.getaxisleft();     leftaxis.addlimitline(line);      barchart.setdata(data);     barchart.setdescription("the expenses chart.");     barchart.animatey(2000);  } 

if found helpful, let me know.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -