Not able to display graph using achartengine. -
Not able to display graph using achartengine. -
i retrieving info database , storing in 2 arrays. 1 array consists of temperature values , other has date . using timechart of achartengine still not able display graph. works when utilize random values x axis , utilize linechart. x axis labels 1970-01-01 5:30:00 . seems database values not beingness taken graph. can plz help?
package com.ti.sensortag; import java.text.decimalformat; import java.text.numberformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import java.util.list; import org.achartengine.chartfactory; import org.achartengine.graphicalview; import org.achartengine.chart.pointstyle; import org.achartengine.model.timeseries; import org.achartengine.model.xymultipleseriesdataset; import org.achartengine.renderer.xymultipleseriesrenderer; import org.achartengine.renderer.xyseriesrenderer; import db.dbhandler; import db.temperature; import android.os.bundle; import android.app.activity; import android.graphics.color; import android.graphics.paint.align; import android.util.log; import android.view.menu; import android.widget.linearlayout; public class temperature_graph extends activity { dbhandler db; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_temperature__graph); graphicalview mchart; db=new dbhandler(getapplicationcontext()); //reading info database list<temperature> temp=db.getalltempreadings(); int arraysize=temp.size(); double tarray[]=new double[arraysize]; //array hold temperature values string tsarray[]=new string[arraysize]; // array hold timestamp values date datearray[]=new date[tsarray.length]; // array hold timestamp (string) converted (date) for(int i=0;i<arraysize;i++){ tarray[i]=double.parsedouble(temp.get(i).gettemperature()); tsarray[i]=temp.get(i).gettimestamp(); //converting string date simpledateformat sdf=new simpledateformat("dd-mm-yyyy hh:mm:ss"); seek { date result=sdf.parse(tsarray[i]); datearray[i]= result; log.d("datearray",string.valueof(datearray[i])); } grab (parseexception e) { // todo auto-generated grab block e.printstacktrace(); } } //timeseries timeseries tseries=new timeseries("temperature"); timeseries hseries=new timeseries("35"); // hypothermia timeseries fseries=new timeseries("37.5"); // fever timeseries nseries=new timeseries("normal-36.4"); double harray[]=new double[arraysize]; double farray[]=new double[arraysize]; double narray[]=new double[arraysize]; double numbers[]=new double[arraysize]; for(int i=0;i<tsarray.length;i++){ harray[i]=35; farray[i]=37.5; narray[i]=36.4; //adding values timeseries tseries.add(datearray[i], tarray[i]); hseries.add(datearray[i], harray[i]); nseries.add(datearray[i], narray[i]); fseries.add(datearray[i], farray[i]); } //dataset xymultipleseriesdataset dataset=new xymultipleseriesdataset(); //adding series dataset dataset.addseries(tseries); dataset.addseries(hseries); dataset.addseries(nseries); dataset.addseries(fseries); //properties of temperature series xyseriesrenderer trenderer=new xyseriesrenderer(); trenderer.setcolor(color.yellow); trenderer.setpointstyle(pointstyle.diamond); trenderer.setfillpoints(true); final numberformat tempvalueformat=new decimalformat("##.##"); trenderer.setchartvaluesformat(tempvalueformat); trenderer.setchartvaluestextsize(20); trenderer.setdisplaychartvalues(true); trenderer.setchartvaluesspacing((float)0.5); trenderer.setchartvaluestextsize(20); //properties of hseries xyseriesrenderer hrenderer=new xyseriesrenderer(); hrenderer.setcolor(color.magenta); hrenderer.setlinewidth(3); //properties of fseries xyseriesrenderer frenderer=new xyseriesrenderer(); frenderer.setcolor(color.red); frenderer.setlinewidth(3); //properties of nseries xyseriesrenderer nrenderer=new xyseriesrenderer(); nrenderer.setcolor(color.cyan); nrenderer.setlinewidth(3); frenderer.setlinewidth(3); //properties of chart xymultipleseriesrenderer mrenderer=new xymultipleseriesrenderer(); mrenderer.setbackgroundcolor(color.black); mrenderer.setpointsize(5); mrenderer.setlabelscolor(color.green); mrenderer.setcharttitle("temperature line graph"); mrenderer.setcharttitletextsize(30); mrenderer.setaxescolor(color.white); mrenderer.setapplybackgroundcolor(true); mrenderer.setaxistitletextsize(15); mrenderer.setxtitle("time"); mrenderer.setytitle("temperature"); // mrenderer.setzoombuttonsvisible(true); mrenderer.setxlabelsangle(10); mrenderer.setylabelsalign(align.left); mrenderer.setylabels(15); mrenderer.setxlabels(10); mrenderer.setxlabelsalign(align.right); mrenderer.setylabelsangle(10); mrenderer.setxaxismin(0); mrenderer.setxaxismax(30); mrenderer.setshowgridx(true); mrenderer.setshowgridy(true); mrenderer.setxlabelsalign(align.center); mrenderer.setlabelstextsize(20); //mrenderer.setlegendtextsize(20); // mrenderer.setlegendheight(50); //adding series renderer mrenderer.addseriesrenderer(trenderer); mrenderer.addseriesrenderer(hrenderer); mrenderer.addseriesrenderer(nrenderer); mrenderer.addseriesrenderer(frenderer); linearlayout layout=(linearlayout)findviewbyid(r.id.graph); mchart=(graphicalview)chartfactory.gettimechartview(getbasecontext(), dataset, mrenderer, "yyyy-mm-dd hh:mm:ss"); layout.addview(mchart); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.temperature__graph, menu); homecoming true; } }
timechart not seem back upwards displaying minimum number of points @ time. when removed mrenderer.setxaxismin(0); mrenderer.setxaxismax(30); graph got displayed. there way display number of points @ time using timechart?
achartengine
Comments
Post a Comment