android - Dataset entry are longer than x axis in MpAndroid chart? -


am trying create barchart (grouped datasets) chart using mpandroid chart while setting values using real time data sqlite whenver fetch data webservice , trying set value chart getting error dataset entry longer x axis values of chartdata object here code:

import android.database.cursor; import android.graphics.color; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.loadermanager; import android.support.v4.content.cursorloader; import android.support.v4.content.loader; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  import com.android.volley.requestqueue; import com.github.mikephil.charting.charts.barchart; import com.github.mikephil.charting.data.bardata; import com.github.mikephil.charting.data.bardataset; import com.github.mikephil.charting.data.barentry; import com.github.mikephil.charting.interfaces.datasets.ibardataset;  import java.util.arraylist; import java.util.list;  import sqlitedatabase.timetrackerdao; import model.dashboardmodelcommercial;  /**  * created 4264 on 27-06-2016.  */ public class dashboardcommercial extends fragment implements loadermanager.loadercallbacks<cursor>{     requestqueue mrequestqueue;     timetrackerdao timetrackerdao;     private int dashboard = 1;     cursor c;     list<dashboardmodelcommercial>listobj;     view   view;     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view = inflater.inflate(r.layout.fragment_commercial, container, false);          barchart chart = (barchart)view. findviewbyid(r.id.chart);         timetrackerdao=new timetrackerdao(getcontext().getapplicationcontext());         listobj=new arraylist<>();          getloadermanager().initloader(dashboard, null, this);         return view;     }        /*private arraylist<ibardataset> getdataset() {         arraylist<ibardataset> datasets = null;          arraylist<barentry> valueset1 = new arraylist<>();         barentry v1e1 = new barentry(110.000f, 0); // jan         valueset1.add(v1e1);         barentry v1e2 = new barentry(40.000f, 1); // feb         valueset1.add(v1e2);         barentry v1e3 = new barentry(60.000f, 2); // mar         valueset1.add(v1e3);         barentry v1e4 = new barentry(30.000f, 3); // apr         valueset1.add(v1e4);         barentry v1e5 = new barentry(90.000f, 4); // may         valueset1.add(v1e5);         barentry v1e6 = new barentry(100.000f, 5); // jun         valueset1.add(v1e6);          arraylist<barentry> valueset2 = new arraylist<>();         barentry v2e1 = new barentry(150.000f, 0); // jan         valueset2.add(v2e1);         barentry v2e2 = new barentry(90.000f, 1); // feb         valueset2.add(v2e2);         barentry v2e3 = new barentry(120.000f, 2); // mar         valueset2.add(v2e3);         barentry v2e4 = new barentry(60.000f, 3); // apr         valueset2.add(v2e4);         barentry v2e5 = new barentry(20.000f, 4); // may         valueset2.add(v2e5);         barentry v2e6 = new barentry(80.000f, 5); // jun         valueset2.add(v2e6);           arraylist<barentry> valueset3 = new arraylist<>();         barentry v2e= new barentry(150.000f, 0); // jan         valueset3.add(v2e);         barentry v = new barentry(90.000f, 1); // feb         valueset3.add(v);         barentry vv = new barentry(120.000f, 2); // mar         valueset3.add(vv);         barentry vvv = new barentry(60.000f, 3); // apr         valueset3.add(vvv);         barentry vvvv = new barentry(20.000f, 4); // may         valueset3.add(vvvv);         barentry vvvvv = new barentry(80.000f, 5); // jun         valueset3.add(vvvvv);          bardataset bardataset1 = new bardataset(valueset1, "brand 1");         bardataset1.setcolor(color.rgb(0, 155, 0));         bardataset bardataset2 = new bardataset(valueset2, "brand 2");         bardataset2.setcolors(colortemplate.colorful_colors);         bardataset bardataset3 = new bardataset(valueset3, "brand 3");         bardataset3.setcolors(colortemplate.colorful_colors);          datasets = new arraylist<>();         datasets.add(bardataset1);         datasets.add(bardataset2);         datasets.add(bardataset3);         return datasets;     }      private arraylist<string> getxaxisvalues() {         arraylist<string> xaxis = new arraylist<>();         xaxis.add("jan");         xaxis.add("feb");         xaxis.add("mar");         xaxis.add("apr");         xaxis.add("may");         xaxis.add("jun");         return xaxis;     } */     @override     public loader<cursor> oncreateloader(int id, bundle args) {         return new cursorloader(getcontext().getapplicationcontext(), timetrackerdao.db_timetracker_dashboardcommercial, null, null, null, null){              forceloadcontentobserver mobserver=new forceloadcontentobserver();             @override             public cursor loadinbackground() {                   c = timetrackerdao.dashboardcommercial();                 if(c==null){                     log.d("no data", "no data");                 }                  else  {                     c.getcount();                     c.registercontentobserver(mobserver);                     c.setnotificationuri(getcontext().getcontentresolver(), geturi());                  }                 return c;             }             };       }      @override     public void onloadfinished(loader<cursor> loader, cursor data) {         barchart chart = (barchart) view.findviewbyid(r.id.chart);         if (getdataset(data)                 != null) {              bardata data_commercial = new bardata(getxaxisvalues(), getdataset(data));             chart.setdata(data_commercial);             chart.setdescription("my chart");             chart.animatexy(2000, 2000);             chart.invalidate();         }          else {             log.e("err", "err");         }     }      @override     public void onloaderreset(loader<cursor> loader) {      }       private arraylist<ibardataset> getdataset(cursor c) {         arraylist<ibardataset> datasets = null;         arraylist<barentry> valueset1 = new arraylist<>();         list<dashboardmodelcommercial>liststatus=new arraylist<>();          c=timetrackerdao.dashboardcommercialstatus0();         if (c.movetofirst()) {             {                 dashboardmodelcommercial dashboardmodelcommercial=new dashboardmodelcommercial();                 dashboardmodelcommercial.setcount(c.getint(c.getcolumnindex(dashboardmodelcommercial.commercial_count)));                 liststatus.add(dashboardmodelcommercial);             } while (c.movetonext());          }         for(int i=0;i<liststatus.size();i++){             valueset1.add(new barentry(liststatus.get(i).getcount(),i));//status 0         }          arraylist<barentry> valueset2 = new arraylist<>();          list<dashboardmodelcommercial>liststatus1=new arraylist<>();         c=timetrackerdao.dashboardcommercialstatus1();         if (c.movetofirst()) {             {                 dashboardmodelcommercial dashboardmodelcommercial=new dashboardmodelcommercial();                 dashboardmodelcommercial.setcount(c.getint(c.getcolumnindex(dashboardmodelcommercial.commercial_count)));                 liststatus1.add(dashboardmodelcommercial);             } while (c.movetonext());          }         for(int i=0;i<liststatus1.size();i++){             valueset2.add(new barentry(liststatus1.get(i).getcount(),i));//status 0         }          arraylist<barentry> valueset3 = new arraylist<>();         list<dashboardmodelcommercial>liststatus2=new arraylist<>();         c=timetrackerdao.dashboardcommercialstatus2();         if(c.movetofirst()){             {                 {                     dashboardmodelcommercial dashboardmodelcommercial=new dashboardmodelcommercial();                     dashboardmodelcommercial.setcount(c.getint(c.getcolumnindex(dashboardmodelcommercial.commercial_count)));                     liststatus2.add(dashboardmodelcommercial);                 }             }while (c.movetonext());          }         (int i=0;i<liststatus2.size();i++){             valueset3.add(new barentry(liststatus2.get(i).getcount(),i));         }          arraylist<barentry>valueset4=new arraylist<>();         list<dashboardmodelcommercial>liststatus3=new arraylist<>();         c=timetrackerdao.dashboardcommercialstatus3();         if(c.movetofirst()){             {                 {                     dashboardmodelcommercial dashboardmodelcommercial=new dashboardmodelcommercial();                     dashboardmodelcommercial.setcount(c.getint(c.getcolumnindex(dashboardmodelcommercial.commercial_count)));                     liststatus3.add(dashboardmodelcommercial);                 }             }while (c.movetonext());          }         (int i=0;i<liststatus3.size();i++){             valueset4.add(new barentry(liststatus3.get(i).getcount(),i));         }            bardataset bardataset1 = new bardataset(valueset1, "not started");         bardataset1.setcolor(color.rgb(0, 155, 0));         bardataset bardataset2 = new bardataset(valueset2, "in progress");         bardataset2.setcolor(color.rgb(164, 228, 251));         bardataset bardataset3 = new bardataset(valueset3, "completed");         bardataset3.setcolor(color.rgb(242, 247, 158));         bardataset bardataset4 = new bardataset(valueset4, " not completed");         bardataset4.setcolor(color.rgb(200, 220, 170));           datasets = new arraylist<>();         datasets.add(bardataset1);         datasets.add(bardataset2);         datasets.add(bardataset3);         datasets.add(bardataset4);         return datasets;     }     private arraylist<string> getxaxisvalues() {         arraylist<string> xaxis = new arraylist<>();         xaxis.add("billable");         xaxis.add("non billable");          return xaxis;        } } 

i don't know making mistake how recitify if banging head in wall hours can helpme out how resolve problem!

bar entries count , xaxis labels count should equal. adding 2 xaxis labels in getxaxisvalues() method. may getting more 2 bar entries in bardataset.

add xaxis labels equal bar entries count in bardataset.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -