android - I am using achart engine and want to add starting and ending date -
![enter image description here][1] using achartengine graphs plotting in android , want add starting ending date in snapshoot.make enable code date , save data.achar engine use graphs mei how achieve
public class mainactivity extends activity { private graphicalview mchart; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); openchart(); } private void openchart(){ int count = 5; date[] dt = new date[5]; for(int i=0;i<count;i++){ gregoriancalendar gc = new gregoriancalendar(2012, 10, i+1); dt[i] = gc.gettime(); } int[] visits = { 2000,2500,2700,2100,2800}; int[] views = {2200, 2700, 2900, 2800, 3200}; // creating timeseries visits timeseries visitsseries = new timeseries("visits"); // creating timeseries views timeseries viewsseries = new timeseries("views"); // adding data visits , views series for(int i=0;i<dt.length;i++){ visitsseries.add(dt[i], visits[i]); viewsseries.add(dt[i],views[i]); } // creating dataset hold each series xymultipleseriesdataset dataset = new xymultipleseriesdataset(); // adding visits series dataset dataset.addseries(visitsseries); // adding visits series dataset dataset.addseries(viewsseries); // creating xyseriesrenderer customize visitsseries xyseriesrenderer visitsrenderer = new xyseriesrenderer(); visitsrenderer.setcolor(color.white); visitsrenderer.setpointstyle(pointstyle.circle); visitsrenderer.setfillpoints(true); visitsrenderer.setlinewidth(2); visitsrenderer.setdisplaychartvalues(true); // creating xyseriesrenderer customize viewsseries xyseriesrenderer viewsrenderer = new xyseriesrenderer(); viewsrenderer.setcolor(color.yellow); viewsrenderer.setpointstyle(pointstyle.circle); viewsrenderer.setfillpoints(true); viewsrenderer.setlinewidth(2); viewsrenderer.setdisplaychartvalues(true); // creating xymultipleseriesrenderer customize whole chart xymultipleseriesrenderer multirenderer = new xymultipleseriesrenderer(); multirenderer.setcharttitle("visits vs views chart"); multirenderer.setxtitle("days"); multirenderer.setytitle("count"); multirenderer.setzoombuttonsvisible(true); // adding visitsrenderer , viewsrenderer multiplerenderer multirenderer.addseriesrenderer(visitsrenderer); multirenderer.addseriesrenderer(viewsrenderer); // getting reference linearlayout of mainactivity layout linearlayout chartcontainer = (linearlayout) findviewbyid(r.id.chart_container); // creating time chart mchart = (graphicalview) chartfactory.gettimechartview(getbasecontext(), dataset, multirenderer,"dd-mmm-yyyy"); multirenderer.setclickenabled(true); multirenderer.setselectablebuffer(10); // setting click event listener graph mchart.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { format formatter = new simpledateformat("dd-mmm-yyyy"); seriesselection seriesselection = mchart.getcurrentseriesandpoint(); if (seriesselection != null) { int seriesindex = seriesselection.getseriesindex(); string selectedseries="visits"; if(seriesindex==0) selectedseries = "visits"; else selectedseries = "views"; // getting clicked date ( x value ) long clickeddateseconds = (long) seriesselection.getxvalue(); date clickeddate = new date(clickeddateseconds); string strdate = formatter.format(clickeddate); // getting y value int amount = (int) seriesselection.getvalue(); // displaying toast message toast.maketext( getbasecontext(), selectedseries + " on " + strdate + " : " + amount , toast.length_short).show(); } } }); // adding line chart linearlayout chartcontainer.addview(mchart); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.activity_main, menu); return true; } } ![here image ][2]
to add minumim , maximum dates in x axis (if want) :
multirenderer.setxlabels(0); //in order define custom labels multirenderer.setxaxismin(initial_date.size()); multirenderer.setxaxismax(final_date.size());
where final_date must date after last date.
update:
you must use: multirenderer.addxtextlabel(1,"10/04");
and can loop (assuming dates list holds dates) :
for (int i=0;i<dates.size();i++){ multirenderer.addxtextlabel(i,dates.get(i)); }
but must use multirenderer.setxlabels(0); before above in order define labels.
Comments
Post a Comment