android - How to display refresh webservice value in achartengine line chart? -


i have achartengine line graph, displaying values json webservice in line graph. problem when callback asynctask line graph display old values on x y axis. not displaying new values. below code.

public void chardeclaration() {      // chart      linearlayout layout = (linearlayout) findviewbyid(r.id.chart);     if (mychart == null) {          initializechartnew();          mychart = chartfactory.getlinechartview(this, dataset,                 multirenderer);         layout.addview(mychart);     } else {         mychart.repaint();     } }  @suppresswarnings("deprecation") private void initializechartnew() {     // creating xyseries income     fromtemp = new xyseries("temperature");      (int = 0; < temp_time.size(); i++) {         fromtemp.add(i, double.parsedouble(temp_details.get(i)));         system.out.println("temperature details in charts "                 + temp_details.get(i));     }     // creating dataset hold each series     dataset = new xymultipleseriesdataset();     // adding income series dataset     dataset.addseries(fromtemp);        // creating xyseriesrenderer customize incomeseries     from_temprenderer = new xyseriesrenderer();     from_temprenderer.setcolor(color.white);     from_temprenderer.setpointstyle(pointstyle.circle);     from_temprenderer.setfillpoints(true);     from_temprenderer.setlinewidth(2);     from_temprenderer.setchartvaluestextsize(20);     from_temprenderer.setdisplaychartvalues(true);      // creating xyseriesrenderer customize expenseseries      // creating xymultipleseriesrenderer customize whole chart     multirenderer = new xymultipleseriesrenderer();     multirenderer.setmargins(new int[] { 50, 50, 50, 50 });     multirenderer.setylabelsalign(align.right);     multirenderer.setaxistitletextsize(20);     multirenderer.setcharttitletextsize(20);     multirenderer.setlabelstextsize(18);     multirenderer.setlegendtextsize(18);     multirenderer.setxlabels(0);      (int k = 0; k < temp_date.size(); k++) {         multirenderer.setcharttitle(temp_date.get(k));         system.out                 .println("temperature date in charts " + temp_date.get(k));     }     multirenderer.setxtitle("time");     multirenderer.setytitle("temperature");     multirenderer.setylabelspadding(5);     multirenderer.setzoombuttonsvisible(true);      multirenderer.setpointsize(5);      (int = 0; < temp_time.size(); i++) {         multirenderer.addxtextlabel(i, temp_time.get(i));      }      system.out.println("value of temp_details " + temp_details.size());      multirenderer.removeseriesrenderer(from_temprenderer);     multirenderer.addseriesrenderer(from_temprenderer);  }  below asynctask  private class temperaturedetails extends asynctask<string, string, string> {      @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(mainactivity_new.this);         pdialog.setmessage("please wait...");         pdialog.setcancelable(false);         pdialog.setindeterminate(false);         pdialog.setcanceledontouchoutside(false);         pdialog.show();          // building_segment_id="";         /*          * temp_details.clear(); date_time.clear(); temp_date.clear();          * temp_time.clear();          */      }      @override     protected string doinbackground(string... params) {         // todo auto-generated method stub         try {             system.out                     .println("temp building seg id" + building_segment_id);             // string temperature_url =             // "http://www.intelatrek.com:98/service1.svc/tempratuelist?beconid=329%20king&date=2015-04-09";             string temp_url = "http://db.stat-systems.co.nz:81/service1.svc/tempraturelist?beconid="                     + building_segment_id + "&date=2015-04-13";             system.out.println("blucatid in asynctask " + blucat_id);             system.out.println("building_segment_id in asynctask "                     + building_segment_id);              temp_details.clear();             date_time.clear();             temp_date.clear();             temp_time.clear();              jsonobject jobject = jsonparser.getjsonfromurl(temp_url);             tempjsonflag = jobject.getstring("flag");             jsonarray jarray = jobject.getjsonarray("temptranslist");             (int = 0; < jarray.length(); i++) {                 jsonobject job = jarray.getjsonobject(i);                  string buildingid = job.getstring("buildingid");                 string buildingsegmentid = job                         .getstring("buildingsegmentid");                 // string customer_id = job.getstring("customer_id");                 string datetime = job.getstring("datetime");                 // string innerlocationid =                 // job.getstring("innerlocationid");                 string temp_date = job.getstring("tempdate");                 string temp_time = job.getstring("temptime");                 string temperature = job.getstring("temperature");                  temp_details.add(temperature);                 date_time.add(datetime);                 temp_date.add(temp_date);                 temp_time.add(temp_time);             }         } catch (exception e) {             e.printstacktrace();         }         return null;     }      @override     protected void onpostexecute(string result) {         // todo auto-generated method stub         super.onpostexecute(result);         if (pdialog != null) {             pdialog.dismiss();         }          (int = 0; < temp_details.size(); i++) {             system.out                     .println("temperature details " + temp_details.get(i));             system.out.println("temperature date time " + date_time.get(i));             system.out.println("temperature temp date " + temp_date.get(i));             system.out.println("temperature temp time " + temp_time.get(i));         }         system.out.println("temp details " + temp_details.size());         system.out.println("temp date time " + date_time.size());         system.out.println("temp temp date " + temp_date.size());         system.out.println("temp temp time " + temp_time.size());         system.out.println("temp json flag " + tempjsonflag);          // if(tempjsonflag.equals("success")){         if (tempe_detail.tostring().equals("")) {             temp_textview_temperature.setvisibility(view.gone);             temp_textview_notfound.setvisibility(view.visible);             imageview_degree.setvisibility(view.gone);              /*              * linearlayout layout = (linearlayout)              * findviewbyid(r.id.chart);              */             chart.setvisibility(view.gone);         } else {             temp_textview_notfound.setvisibility(view.gone);             temp_textview_temperature.setvisibility(view.visible);              temp_textview_temperature.settext(tempe_detail);             temp_textview_temperature.settextsize(70);             imageview_degree.setvisibility(view.visible);             // temp_textview_temperature.setlayoutparams(llp);             /*              * linearlayout layout = (linearlayout)              * findviewbyid(r.id.chart);              */             chart.setvisibility(view.visible);              chardeclaration();         }          if (temp_textview_temperature.gettext().tostring().equals("1")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("2")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("3")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("4")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("5")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("6")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("7")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("8")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else if (temp_textview_temperature.gettext().tostring()                 .equals("9")) {             temp_textview_temperature.setpadding(25, 0, 0, 0);         } else {             temp_textview_temperature.setpadding(0, 0, 0, 0);         }          int dip = (int) typedvalue.applydimension(                 typedvalue.complex_unit_dip, (float) 1, getresources()                         .getdisplaymetrics());          displaymetrics dm = new displaymetrics();         getwindowmanager().getdefaultdisplay().getmetrics(dm);          int widthpixels = dm.widthpixels;         int heightpixels = dm.widthpixels;          float scalefactor = dm.density;          float widthinches = widthpixels / scalefactor;          if (widthinches >= 720) {              // 10" tablet resolutions             if (tempe_detail.tostring().equals("")) {                 temp_textview_temperature.setvisibility(view.gone);                 temp_textview_notfound.setvisibility(view.visible);                 imageview_degree.setvisibility(view.gone);                 // temp_textview_notfound.settext(60);                  chart.setvisibility(view.gone);             } else {                 temp_textview_notfound.setvisibility(view.gone);                 temp_textview_temperature.setvisibility(view.visible);                  temp_textview_temperature.settext(tempe_detail);                  if (getresources().getconfiguration().orientation == configuration.orientation_landscape) {                     // stuff                     temp_textview_temperature.settextsize(70);                     imageview_degree.getlayoutparams().height = 30;                     imageview_degree.getlayoutparams().width = 30;                 } else {                     temp_textview_temperature.settextsize(180);                     imageview_degree.getlayoutparams().height = 50;                     imageview_degree.getlayoutparams().width = 50;                 }                  imageview_degree.setvisibility(view.visible);                  // temp_textview_temperature.setlayoutparams(llp);                  chart.setvisibility(view.visible);                 chardeclaration();             }                if (temp_textview_temperature.gettext().tostring()                     .matches("[0-9.]*")) {                 temp_textview_temperature.setpadding(0, 0, 0, 0);             } else if (temp_textview_temperature.gettext().length() == 3) {                 temp_textview_temperature.setpadding(20, 0, 0, 0);             } else {                 temp_textview_temperature.setpadding(0, 0, 0, 0);             }         } else if (widthinches >= 600) {              // 7" tablet resolutions             if (tempe_detail.tostring().equals("")) {                 temp_textview_temperature.setvisibility(view.gone);                 temp_textview_notfound.setvisibility(view.visible);                 imageview_degree.setvisibility(view.gone);                   chart.setvisibility(view.gone);             } else {                 temp_textview_notfound.setvisibility(view.gone);                 temp_textview_temperature.setvisibility(view.visible);                  temp_textview_temperature.settext(tempe_detail);                 temp_textview_temperature.settextsize(140);                 imageview_degree.setvisibility(view.visible);                 // temp_textview_temperature.setlayoutparams(llp);                  chart.setvisibility(view.visible);                 chardeclaration();             }               if (temp_textview_temperature.gettext().tostring()                     .matches("[0-9.]*")) {                 temp_textview_temperature.setpadding(25, 0, 0, 0);                 if (temp_textview_temperature.gettext().length() == 3) {                       temp_textview_temperature.setpadding(0, 0, 0, 0);                 }             }              else {                 temp_textview_temperature.setpadding(0, 0, 0, 0);             }         }         // }       }  } 

use mychart.repaint(); redraw chart after date has been changed , if repaint doesn't work before repainting chart try using removeallviews() chart's parent layout.

chartlayout.removeallviews(); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -