android - Achartengine Line Graph -


i'm using achartengine create line graph. current month showing second line, last month, isn't showing it. here's lass , logcat: can see logcat dates correct , count previous month. why not showing beyond me.

log cat:

08-07 16:13:43.969: i/projectcaruso(11734): debug startdate: 2013-07-01 enddate: 2013-07-31 08-07 16:13:43.969: i/projectcaruso(11734): count: 9 08-07 16:13:43.979: i/projectcaruso(11734): debug startdate: 2013-08-01 enddate: 2013-08-31 

class:

public class temphistoryfragment extends fragment{     private graphicalview mchartview;     simpledateformat  format = new simpledateformat("yyyy-mm-dd");        @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);      }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,  bundle savedinstancestate) {         if (container == null) {             return null;         }         calendar cal = calendar.getinstance();         calendar cal2 = calendar.getinstance();         simpledateformat month_date = new simpledateformat("mmmmmmmmm");         simpledateformat df = new simpledateformat("yyyy-mm-dd",locale.us);         string month_name = month_date.format(cal.gettime());         arraylist<integer> xarray = new arraylist<integer>();         arraylist<integer> yarray = new arraylist<integer>();         arraylist<integer> xarray2 = new arraylist<integer>();         arraylist<integer> yarray2 = new arraylist<integer>();          cal.add(calendar.month ,-1);         string prev_month_name = month_date.format(cal.gettime());           int daysinmonth = cal.getactualmaximum(calendar.day_of_month);           //***********************************************//         // our first data last month         //***********************************************//         //start date cursor         //cal.add(calendar.month, -1);         cal.set(calendar.date, 1);         string startdate = df.format(cal.gettime());          //end date         cal.set(calendar.date, daysinmonth);         string enddate = df.format(cal.gettime());           log.i("projectcaruso","debug startdate: " + startdate + " enddate: " + enddate);         cursor c = getactivity().getcontentresolver().query(statusprovider.content_uri_charting, null, "? < " + statusdata.key_charting_date + " , ? > " + statusdata.key_charting_date , new string[] {startdate, enddate}, null); //         c.movetofirst();         log.i("projectcaruso","count: " + c.getcount());         if (c.getcount()>0 && c!=null) {             while (c.isafterlast() == false) {                 if ((isnumeric(c.getstring(c.getcolumnindex(statusdata.key_charting_temperature))))) {                   java.util.date date = null;                 int day = 0;                  //get date database                 string datetest = c.getstring(c.getcolumnindex(statusdata.key_charting_date));                   //try reformat date.                 try {                     date = format.parse(datetest);                     day = date.getdate();                 } catch (java.text.parseexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                    xarray.add(day);                  }             c.movetonext();             }          }          int[] x = new int[xarray.size()];         (int = 0; < xarray.size(); i++) {             x[i] = xarray.get(i);         }          int[] y = new int[yarray.size()];         (int = 0; < yarray.size(); i++) {             y[i] = yarray.get(i);         }          timeseries series = new timeseries(prev_month_name);          for( int = 0; < y.length; i++)         {             series.add(x[i], y[i]);         }           //***********************************************//         // our second data month         //***********************************************//         //start date cursor         cal2.set(calendar.date, 1);         string startdate2 = df.format(cal2.gettime());          //end date         cal2.set(calendar.date, daysinmonth);         string enddate2 = df.format(cal2.gettime());           log.i("projectcaruso","debug startdate: " + startdate2 + " enddate: " + enddate2);         cursor c2 = getactivity().getcontentresolver().query(statusprovider.content_uri_charting, null, "? < " + statusdata.key_charting_date + " , ? > " + statusdata.key_charting_date , new string[] {startdate2, enddate2}, null); //         c2.movetofirst();           if (c2.getcount()>0 && c2!=null) {             while (c2.isafterlast() == false)  {                 if (isnumeric(c2.getstring(c2.getcolumnindex(statusdata.key_charting_temperature)))){                      yarray2.add(c2.getint(c2.getcolumnindex(statusdata.key_charting_temperature)));                      java.util.date date = null;                     int day = 0;                      //get date database                     string datetest = c2.getstring(c2.getcolumnindex(statusdata.key_charting_date));                       //try reformat date.                     try {                         date = format.parse(datetest);                         day = date.getdate();                     } catch (java.text.parseexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                        xarray2.add(day);                  }             c2.movetonext();             }          }           int[] x2 = new int[xarray2.size()];         (int = 0; < xarray2.size(); i++) {             x2[i] = xarray2.get(i);         }          int[] y2 = new int[yarray2.size()];         (int = 0; < yarray2.size(); i++) {             y2[i] = yarray2.get(i);         }          timeseries series2 = new timeseries(month_name);          for( int = 0; < x2.length; i++)         {             series2.add(x2[i], y2[i]);         }            xymultipleseriesdataset dataset = new xymultipleseriesdataset();         dataset.addseries(series);         dataset.addseries(series2);          xymultipleseriesrenderer mrenderer = new xymultipleseriesrenderer(); // holds collection of xyseriesrenderer , customizes graph         xyseriesrenderer renderer = new xyseriesrenderer(); // used customize line 1         xyseriesrenderer renderer2 = new xyseriesrenderer(); // used customize line 2         mrenderer.addseriesrenderer(renderer);         mrenderer.addseriesrenderer(renderer2);          // customization time line 1!         renderer.setcolor(getresources().getcolor(r.color.complementary));         renderer.setpointstyle(pointstyle.square);         renderer.setfillpoints(true);          // customization time line 2!         renderer2.setcolor(getresources().getcolor(r.color.base));         renderer2.setpointstyle(pointstyle.diamond);         renderer2.setfillpoints(true);          mchartview = chartfactory.getlinechartview(getactivity(), dataset, mrenderer);          //set chart title , labels         mrenderer.setcharttitle("temperature tracking");         mrenderer.setcharttitletextsize(getresources().getdimension(r.dimen.largetext));         mrenderer.setlabelscolor(getresources().getcolor(r.color.primarytextdark));          //yaxis of temp         mrenderer.setytitle("temperature", 0);         mrenderer.setyaxismin(80, 0);         mrenderer.setyaxismax(110, 0);         mrenderer.setylabelsalign(align.center);         mrenderer.setylabelscolor(0, getresources().getcolor(r.color.primarytextdark));           //xaxis of month         mrenderer.setxlabels(20);         mrenderer.setxtitle(month_name);                 mrenderer.setxaxismin(1);         mrenderer.setxaxismax(daysinmonth);         mrenderer.setxlabelscolor(getresources().getcolor(r.color.primarytextdark));           //set display         mrenderer.setmarginscolor(getresources().getcolor(r.color.transparent));         mrenderer.setshowcustomtextgrid(true);         mrenderer.setaxistitletextsize(getresources().getdimension(r.dimen.mediumtext));         mrenderer.setlabelstextsize(getresources().getdimension(r.dimen.smallmediumtext));         mrenderer.setpanenabled(false, false);         mrenderer.setclickenabled(false);         mrenderer.setzoomenabled(false, false);           return mchartview;      }      @suppresswarnings("unused")     public static boolean isnumeric(string str)       {         try         {           double d = double.parsedouble(str);         }         catch(numberformatexception nfe)         {           return false;         }         return true;       }  } 

oh , here colors:

    <color name ="base">#51bbc2</color>     <color name ="complementary">#c25951</color> 

the result

thanks @dan lead me solution. went , logged points make sure right values getting placed in right array , come find out yarray.add(c.getint(c.getcolumnindex(statusdata.key_charting_temperature))); somehow got deleted. works! yay!


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -