Graph In Android Using AChartEngine -
problem not able fit graph according screen. of portion of graph cutting right side.i tried lot set margin right nothing works me.as can see in attached image last bar cutting half. please me.
*layout.xml <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linear1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" android:orientation="vertical" > <tablelayout android:id="@+id/table1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:shrinkcolumns="6" android:stretchcolumns="*" > <tablerow android:id="@+id/tablerow1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#4cc1d2" android:padding="4dip" > <imagebutton android:layout_width="match_parent" android:layout_height="40dp" android:layout_gravity="left" android:layout_span="1" android:onclick="gotoback" android:background="#4cc1d2" android:src="@drawable/backb" /> <textview android:id="@+id/currentmonth" android:layout_width="wrap_content" android:layout_height="40dp" android:layout_span="5" android:gravity="left" android:text="how want track" android:textcolor="#ffffff" android:layout_marginleft="-18dp" android:textsize="21sp" android:textstyle="bold" /> </tablerow> </tablelayout> <tablelayout android:id="@+id/table2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:shrinkcolumns="9" android:stretchcolumns="*" > <tablerow android:id="@+id/tablerow4" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#e6e6e6" android:padding="5dip" > <imagebutton android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_span="3" android:background="#ffffff" android:gravity="center" android:src="@drawable/lstweek" /> <imagebutton android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="3dp" android:layout_span="3" android:background="#ffffff" android:clickable="true" android:onclick="getmonth" android:src="@drawable/lstm" /> <imagebutton android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="3dp" android:layout_marginright="10dp" android:layout_span="3" android:background="#4cc1d2" android:gravity="center" android:onclick="getmonth1" android:src="@drawable/all" /> </tablerow> </tablelayout> <linearlayout android:id="@+id/chart_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/white" android:orientation="vertical" > <view android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <button android:id="@+id/logs7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#4cc1d2" android:onclick="alllogs" android:text="view logs" android:textcolor="#ffffff" android:textsize="22dp" android:textstyle="bold" /> </linearlayout> </linearlayout>* activity java file. public class calorieconsumedtrackeractivity extends activity { private graphicalview mchart; jsonarray dailydata = null; private progressdialog progressdialog; private static string url_display_user ; jsonparser jsonparser = new jsonparser(); private static final string tag_success = "success"; private static final string tag_response = "getdata"; jsonarray graphdatas = null; arraylist<hashmap<string, string>> getdata; private static final string tag_message = "message"; string userid=null; string[] mmonth = new string[7] ; string[] datefromdb = new string[7] ; int[] x = {1,2,3,4,5,6,7}; int[] target = new int[7]; int[] consumed = new int[7]; int[]showtarget=new int[7]; int[]showconsumed=new int[7]; xyseries incomeseries = new xyseries("target"); // creating xyseries expense xyseries expenseseries = new xyseries("consumed"); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_calories_consumed ); getdata=new arraylist<hashmap<string,string>>(); databasehandler db=new databasehandler(getapplicationcontext()); hashmap<string,string> user = new hashmap<string,string>(); user=db.getuserdetails(); userid=user.get("userid"); calendar mycalendar = calendar.getinstance(); mycalendar.set(mycalendar.gettime().getyear()+1900,mycalendar.gettime().getmonth() , mycalendar.gettime().getdate()); (int = 6; >=0; i--) { mycalendar.add(calendar.day_of_year, -1); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); string date = sdf.format(mycalendar.gettime()); system.out.println(date); mmonth[i]=date; } new getgraphdata().execute(); } private void openchart(){ } class getgraphdata extends asynctask<string, string, string> { @override protected void onpreexecute() { super.onpreexecute(); progressdialog = progressdialog.show(calorieconsumedtrackeractivity.this, "wait", "fetching..."); } @override protected string doinbackground(string... params) { url_display_user = "http://www.bharatwellness.com/getgraphdata.php"; // building parameters list<namevaluepair> parametres = new arraylist<namevaluepair>(); parametres.add(new basicnamevaluepair("userid", userid)); // getting json string url jsonobject json = jsonparser.makehttprequest(url_display_user, "get", parametres); // check log cat json reponse log.d("all data : ", json.tostring()); try { // checking success tag int success = json.getint(tag_success); jsonobject c=null; if (success == 1) { int i; int cal=0; // products found // getting array of products graphdatas = json.getjsonarray(tag_response); // looping through response (i = 0; < graphdatas.length(); i++) { c = graphdatas.getjsonobject(i); // storing each json item in variable string createddate = c.getstring("createddate"); datefromdb[i]=createddate; string caloriegoal = c.getstring("caloriegoal"); string calorieconsumed = c.getstring("calorieconsumed"); double cgoal=double.parsedouble(caloriegoal); cal=(int) math.round(cgoal); target[i]=cal; double csumed=double.parsedouble(calorieconsumed); int calc=(int) math.round(csumed); consumed[i]=calc; } for(int x=0;x<mmonth.length;x++){ for(int y=0;y<datefromdb.length;y++){ if(mmonth[x].equals(datefromdb[y])){ showconsumed[x]=consumed[y]; showtarget[x]=target[y]; } if(showtarget[x]==0){ showtarget[x]=cal; } } } // creating xyseries income // adding data income , expense series for(int j=0;j<x.length;j++){ incomeseries.add(x[j], showtarget[j]); expenseseries.add(x[j],showconsumed[j]); } runonuithread(new runnable() { public void run() { // creating dataset hold each series xymultipleseriesdataset dataset = new xymultipleseriesdataset(); // adding income series dataset dataset.addseries(incomeseries); // adding expense series dataset dataset.addseries(expenseseries); // creating xyseriesrenderer customize incomeseries xyseriesrenderer incomerenderer = new xyseriesrenderer(); incomerenderer.setcolor(color.parsecolor("#04b431")); incomerenderer.setpointstyle(pointstyle.circle); incomerenderer.setfillpoints(true); incomerenderer.setlinewidth(2); incomerenderer.setchartvaluestextsize(20); incomerenderer.setdisplaychartvalues(true); // creating xyseriesrenderer customize expenseseries xyseriesrenderer expenserenderer = new xyseriesrenderer(); expenserenderer.setcolor(color.parsecolor("#ff8000")); expenserenderer.setpointstyle(pointstyle.circle); expenserenderer.setfillpoints(true); expenserenderer.setlinewidth(2); expenserenderer.setchartvaluestextsize(20); expenserenderer.setdisplaychartvalues(true); for(int z=0;z<mmonth.length;z++){ string createddate=mmonth[z]; string month=createddate.substring(5, 7); system.out.println(month); int m=integer.parseint(month); system.out.println(m); switch (m) { case 1: month="jan"; break; case 2: month="feb"; break; case 3: month="mar"; break; case 4: month="apr"; break; case 5: month="may"; break; case 6: month="june"; break; case 7: month="july"; break; case 8: month="aug"; break; case 9: month="sep"; break; case 10: month="oct"; break; case 11: month="nov"; break; case 12: month="dec"; break; } string day=createddate.substring(8, 10); string finaldate= day+" "+month; mmonth[z]=finaldate ; } // creating xymultipleseriesrenderer customize whole chart xymultipleseriesrenderer multirenderer = new xymultipleseriesrenderer(); multirenderer.setaxistitletextsize(30); multirenderer.setbackgroundcolor(color.white); multirenderer.setaxescolor(color.white); multirenderer.setapplybackgroundcolor(true); multirenderer.setxlabels(0); multirenderer.setcharttitle("calories consumed progress chart"); multirenderer.setgridcolor(color.white); multirenderer.setxtitle(""); multirenderer.setytitle("calories"); multirenderer.setzoombuttonsvisible(true); multirenderer.setbarspacing(4); multirenderer.setpanenabled(false, false); multirenderer.setlabelstextsize(20); multirenderer.setaxescolor(color.black); multirenderer.setxlabelscolor(color.black); multirenderer.setyaxismax(3000); multirenderer.setyaxismin(0); multirenderer.setylabelscolor(0, color.black); double panlimits[]={20,20,20,20}; multirenderer.setpanlimits(panlimits); multirenderer.setmarginscolor(color.white); for(int i=0;i<mmonth.length;i++){ multirenderer.addxtextlabel(i+1, mmonth[i]); multirenderer.setaxistitletextsize(20); int mar[]={20,20,20,20}; multirenderer.setmargins(mar); multirenderer.setgridcolor(color.ltgray); } // adding incomerenderer , expenserenderer multiplerenderer // note: order of adding dataseries dataset , renderers multiplerenderer // should same multirenderer.addseriesrenderer(incomerenderer); multirenderer.addseriesrenderer(expenserenderer); multirenderer.setpanenabled(false); // getting reference linearlayout of mainactivity layout linearlayout chartcontainer = (linearlayout) findviewbyid(r.id.chart_container); chartcontainer.setbackgroundcolor(color.white); linearlayout.layoutparams layoutparams = new linearlayout.layoutparams( linearlayout.layoutparams.wrap_content, linearlayout.layoutparams.wrap_content); linearlayout con = (linearlayout) findviewbyid(r.id.linear1); con.setbackgroundcolor(color.white); // specifying chart types drawn in graph // number of data series , number of types should same // order of data series , chart type same string[] types = new string[] { linechart.type, barchart.type }; // creating combined chart chart types specified in types array mchart = (graphicalview) chartfactory.getcombinedxychartview(getbasecontext(), dataset, multirenderer, types); mchart.setbackgroundcolor(color.white); multirenderer.setclickenabled(true); multirenderer.setselectablebuffer(10); multirenderer.setpanenabled(false); mchart.setminimumwidth(100); // adding combined chart linearlayout chartcontainer.addview(mchart,layoutparams); }}); return json.getstring(tag_message); } else { return json.getstring(tag_message); } } catch (jsonexception e) { e.printstacktrace(); } return null; } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string result) { // dismiss dialog after getting products progressdialog.dismiss(); // updating ui background thread toast.maketext(getbasecontext(), result, toast.length_long).show(); } } } ![enter image description here][2]