android - how to group two barchat from mpandroidchart lib -
i want display in groups of 2 barcharts following barcharts:
any feedback appreciate.
here code:
public class barchartactivitymultidataset extends demobase implements onseekbarchangelistener { private barchart mchart; private seekbar mseekbarx, mseekbary; private textview tvx, tvy; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_barchart); tvx = (textview) findviewbyid(r.id.tvxmax); tvy = (textview) findviewbyid(r.id.tvymax); mseekbarx = (seekbar) findviewbyid(r.id.seekbar1); mseekbarx.setonseekbarchangelistener(this); mseekbary = (seekbar) findviewbyid(r.id.seekbar2); mseekbary.setonseekbarchangelistener(this); mchart = (barchart) findviewbyid(r.id.chart1); mchart.setdescription(""); colortemplate ct = new colortemplate(); // add colors first dataset ct.adddatasetcolors(new int[]{ r.color.colorful_5}, this); // second dataset has 1 color ct.adddatasetcolors(new int[] { r.color.greens_2 }, this); // add colors third dataset //ct.adddatasetcolors(colortemplate.colorful_colors, this); mchart.setcolortemplate(ct); mchart.setbarspace(30f); // disable drawing of values mchart.setdrawyvalues(false); // disable 3d mchart.set3denabled(false); mchart.setylabelcount(10); // scaling can done on x- , y-axis separately mchart.setpinchzoom(false); // mchart.setdrawlegend(false); mseekbarx.setprogress(45); mseekbary.setprogress(100); legend l = mchart.getlegend(); l.setposition(legendposition.right_of_chart); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.bar, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.actiontogglevalues: { if (mchart.isdrawyvaluesenabled()) mchart.setdrawyvalues(false); else mchart.setdrawyvalues(true); mchart.invalidate(); break; } case r.id.actiontogglepinch: { if (mchart.ispinchzoomenabled()) mchart.setpinchzoom(false); else mchart.setpinchzoom(true); mchart.invalidate(); break; } case r.id.actiontoggle3d: { if (mchart.is3denabled()) mchart.set3denabled(false); else mchart.set3denabled(true); mchart.invalidate(); break; } case r.id.actiontogglehighlight: { if (mchart.ishighlightenabled()) mchart.sethighlightenabled(false); else mchart.sethighlightenabled(true); mchart.invalidate(); break; } case r.id.actiontogglehighlightarrow: { if (mchart.isdrawhighlightarrowenabled()) mchart.setdrawhighlightarrow(false); else mchart.setdrawhighlightarrow(true); mchart.invalidate(); break; } case r.id.actiontogglestartzero: { if (mchart.isstartatzeroenabled()) mchart.setstartatzero(false); else mchart.setstartatzero(true); mchart.invalidate(); break; } case r.id.actiontoggleadjustxlegend: { xlabels xlabels = mchart.getxlabels(); if (xlabels.isadjustxlabelsenabled()) xlabels.setadjustxlabels(false); else xlabels.setadjustxlabels(true); mchart.invalidate(); break; } case r.id.actionsave: { // mchart.savetogallery("title"+system.currenttimemillis()); mchart.savetopath("title" + system.currenttimemillis(), ""); break; } } return true; } @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { tvx.settext("" + (mseekbarx.getprogress() + 1)); tvy.settext("" + (mseekbary.getprogress())); arraylist<string> xvals = new arraylist<string>(); (int = 0; < mseekbarx.getprogress(); i++) { xvals.add((i) + ""); } arraylist<entry> yvals1 = new arraylist<entry>(); arraylist<entry> yvals2 = new arraylist<entry>(); // arraylist<entry> yvals3 = new arraylist<entry>(); (int = 0; < mseekbarx.getprogress() / 3; i++) { float val = (float) (math.random() * mseekbary.getprogress()) + 3; yvals1.add(new entry(val, i)); } (int = mseekbarx.getprogress() / 3; < mseekbarx.getprogress() / 3 ; i++) { float val = (float) (math.random() * mseekbary.getprogress()) + 3; yvals2.add(new entry(val, i)); } // create 3 datasets different types dataset set1 = new dataset(yvals1, "finished packages"); dataset set2 = new dataset(yvals2, "in work packages"); //dataset set3 = new dataset(yvals3, "company c"); arraylist<dataset> datasets = new arraylist<dataset>(); datasets.add(set1); datasets.add(set2); // datasets.add(set3); chartdata data = new chartdata(xvals, datasets); mchart.setdata(data); mchart.invalidate(); } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } @override public void onstoptrackingtouch(seekbar seekbar) { // todo auto-generated method stub } }
i updated following class barchartactivitymultidataset above code.
best regards, aurelian
public class barchartactivitymultidataset extends demobase implements onseekbarchangelistener { private barchart mchart; private seekbar mseekbarx, mseekbary; private textview tvx, tvy; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_barchart); tvx = (textview) findviewbyid(r.id.tvxmax); tvy = (textview) findviewbyid(r.id.tvymax); mseekbarx = (seekbar) findviewbyid(r.id.seekbar1); mseekbarx.setonseekbarchangelistener(this); mseekbary = (seekbar) findviewbyid(r.id.seekbar2); mseekbary.setonseekbarchangelistener(this); mchart = (barchart) findviewbyid(r.id.chart1); mchart.setdescription(""); colortemplate ct = new colortemplate(); // add colors first dataset ct.adddatasetcolors(new int[]{ r.color.colorful_5}, this); // second dataset has 1 color ct.adddatasetcolors(new int[] { r.color.greens_2 }, this); // add colors third dataset //ct.adddatasetcolors(colortemplate.colorful_colors, this); mchart.setcolortemplate(ct); mchart.setbarspace(30f); // disable drawing of values mchart.setdrawyvalues(false); // disable 3d mchart.set3denabled(false); mchart.setylabelcount(10); // scaling can done on x- , y-axis separately mchart.setpinchzoom(false); // mchart.setdrawlegend(false); mseekbarx.setprogress(45); mseekbary.setprogress(100); legend l = mchart.getlegend(); l.setposition(legendposition.right_of_chart); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.bar, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.actiontogglevalues: { if (mchart.isdrawyvaluesenabled()) mchart.setdrawyvalues(false); else mchart.setdrawyvalues(true); mchart.invalidate(); break; } case r.id.actiontogglepinch: { if (mchart.ispinchzoomenabled()) mchart.setpinchzoom(false); else mchart.setpinchzoom(true); mchart.invalidate(); break; } case r.id.actiontoggle3d: { if (mchart.is3denabled()) mchart.set3denabled(false); else mchart.set3denabled(true); mchart.invalidate(); break; } case r.id.actiontogglehighlight: { if (mchart.ishighlightenabled()) mchart.sethighlightenabled(false); else mchart.sethighlightenabled(true); mchart.invalidate(); break; } case r.id.actiontogglehighlightarrow: { if (mchart.isdrawhighlightarrowenabled()) mchart.setdrawhighlightarrow(false); else mchart.setdrawhighlightarrow(true); mchart.invalidate(); break; } case r.id.actiontogglestartzero: { if (mchart.isstartatzeroenabled()) mchart.setstartatzero(false); else mchart.setstartatzero(true); mchart.invalidate(); break; } case r.id.actiontoggleadjustxlegend: { xlabels xlabels = mchart.getxlabels(); if (xlabels.isadjustxlabelsenabled()) xlabels.setadjustxlabels(false); else xlabels.setadjustxlabels(true); mchart.invalidate(); break; } case r.id.actionsave: { // mchart.savetogallery("title"+system.currenttimemillis()); mchart.savetopath("title" + system.currenttimemillis(), ""); break; } } return true; } @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { tvx.settext("" + (mseekbarx.getprogress() + 1)); tvy.settext("" + (mseekbary.getprogress())); arraylist<string> xvals = new arraylist<string>(); (int = 0; < mseekbarx.getprogress(); i++) { xvals.add((i) + ""); } arraylist<entry> yvals1 = new arraylist<entry>(); arraylist<entry> yvals2 = new arraylist<entry>();
// arraylist yvals3 = new arraylist();
for (int = 0; < 7; i++) { if (i%2 == 0) { yvals1.add(new entry(30, i)); } else { yvals2.add(new entry(70, i)); } } // create 3 datasets different types dataset set1 = new dataset(yvals1, "finished packages"); dataset set2 = new dataset(yvals2, "in work packages"); //dataset set3 = new dataset(yvals3, "company c"); arraylist<dataset> datasets = new arraylist<dataset>(); datasets.add(set1); datasets.add(set2); // datasets.add(set3); chartdata data = new chartdata(xvals, datasets); mchart.setdata(data); mchart.invalidate(); } @override public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } @override public void onstoptrackingtouch(seekbar seekbar) { // todo auto-generated method stub } }
Comments
Post a Comment