I have an application where the user enters data in edittext and presses the save button.
By pressing 'save' I save in a file the user data (in one column) and the current date (in the other column).
Then , I press another button and make the plot (using achartengine) date (x axis) data (y axis).
So, entering data during a day ,results in saving for example: "1" (user data) -> 20/4/2013 , "2" -> 20/4/2013 , "3" -> 20/4/2013.
And in plot I have 3 points in y axis (ok) and 3 points in x axis (not ok).
I want to have one point in x axis because the data where entered in the same day.
I save data :
public void savefunc(){
SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");
Date d=new Date();
String formattedDate=thedate.format(d);
Log.d("tag","format"+formattedDate);
dates_Strings.add(formattedDate);
double thedata=Double.parseDouble(value.getText().toString().trim());
mydata.add(thedata);
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard, "MyFiles");
directory.mkdirs();
File file = new File(directory, filename);
FileOutputStream fos;
//saving them
try {
fos = new FileOutputStream(file);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
for (int i=0;i<mydata.size();i++){
bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
}
...
How can I save the user data during a day ?
Maybe some check here : Date d=new Date();
? To check if it is the same day.
Or here : bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
But I can't figure.
For example I enter data " 1" , "2" ,"3" in date "20/4/2013".
This is what I get now using my code: This is what I get now http://i35.tinypic.com/2rmsck5.png
But i require graph like below: data entered on same day should be put together:: This is what I want http://i38.tinypic.com/255p5i9.png
---------------UPDATE--------------------------------------------------
mRenderer.setXLabels(0);
for (int i=0;i<mydata.size();i++){
mRenderer.addXTextLabel(i,dates_Strings.get(i));
Date lastDate=null;
String lastdate="";
try{
// the initial date
Date initialDate=formatter.parse(dates_Strings.get(mydata.size()-1));
Calendar c = Calendar.getInstance();
c.setTime(initialDate);
c.add(Calendar.DATE, 1); // increase date by one
lastDate =c.getTime();
}catch ...
}
mRenderer.setXAxisMax(lastDate.getTime());
mRenderer.addXTextLabel(i,dates_Strings.get(i));
}