在一天保存用户数据(在同一天 - >许多用户数据) [英] save user data during a day (the same day -> many user data)
问题描述
我有用户在其中输入中的EditText和$ P $数据的应用程序psses保存按钮。
通过pressing保存我保存在一个文件中的用户数据(一列)和当前日期(在其他列)。
然后,我preSS另一个按钮,使情节(使用achartengine)日期(X轴)数据(Y轴)。
所以,在一天中输入数据,结果在节省例如:1(用户数据) - > 20/4/2013,2 - > 20/4/2013,3 - 20 /二千零十三分之四。
而在情节我有3个Y轴(OK)和3点(X轴)(不正常)。
我想在X轴上一个点,因为那里在同一天输入的数据。
我保存的数据:
公共无效savefunc(){
SimpleDateFormat的thedate =新的SimpleDateFormat(DD / MM / YYYY);
日期D =新的日期();
字符串formattedDate = thedate.format(D);
Log.d(标签,格式+ formattedDate);
dates_Strings.add(formattedDate);
双海图= Double.parseDouble(。value.getText()的toString()修剪());
mydata.add(海图);
文件SD卡= Environment.getExternalStorageDirectory();
文件目录=新的文件(SD卡,MYFILES);
directory.mkdirs();
档案文件=新的文件(目录,文件名);
FileOutputStream中FOS;
//保存它们
尝试 {
FOS =新的FileOutputStream(文件);
BufferedWriter将体重=新的BufferedWriter(新OutputStreamWriter(FOS));
的for(int i = 0; I< mydata.size();我++){
bw.write(mydata.get(ⅰ)+,+ dates_Strings.get(ⅰ)+\ñ);
}
...
在一天
我如何保存用户的数据?
也许有些检查在这里:日期D =新的日期();
?要检查它是否是同一天。
或者点击这里: bw.write(mydata.get(我)+,+ dates_Strings.get(我)+\ N);
但我想不通。
例如我输入数据1,2,3日期20/4/2013。
这就是我现在得到用我的code:
但我需要图如下图所示:应该放在一起::记入当天的数据
---------------更新------------------------------- -------------------
mRenderer.setXLabels(0);
的for(int i = 0; I< mydata.size();我++){
mRenderer.addXTextLabel(ⅰ,dates_Strings.get(ⅰ));
日期lastDate = NULL;
字符串lastdate =;
尝试{
//初始日期
日期initialDate = formatter.parse(dates_Strings.get(mydata.size() - 1));
日历C = Calendar.getInstance();
c.setTime(initialDate);
c.add(Calendar.DATE,1); //增加日期由一个
lastDate = c.getTime();
}抓住 ...
}
mRenderer.setXAxisMax(lastDate.getTime());
mRenderer.addXTextLabel(ⅰ,dates_Strings.get(ⅰ));
}
这是一个AChartEngine问题确实如此。必须保持在的ArrayList
取值使用内部模型和这些问题不存在。在某些时候,有一个社区的努力,使AChartEngine快了很多的数据点。在这一点上,该模型开始使用地图
而不是一个的ArrayList
。此实现prevented具有相同的X值增加数倍。然而,为了解决这个问题,我想补充一个很小的值X,如果它已经存在。在您的例子,第一个值 20/04/2013 00:00:00.0
,第二个是在 20/04/2013 00: 00:00.001
第三个是 20/04/2013 00:00:00.002
现在,解决你的问题是有一个更广泛的在X轴上。
renderer.setXAxisMax(someDate.getTime());
其中, someDate
可以像 21/04/2013
。
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:
But i require graph like below: data entered on same day should be put together::
---------------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));
}
This is an AChartEngine issue indeed. The internal model used to be kept in ArrayList
s and these issues didn't exist. At some point there was a community effort to make AChartEngine faster with a lot of data points. At that point, the model started to use a Map
instead of an ArrayList
. This implementation prevented having the same X value added several times. However, in order to fix this, I add a very small value to X, if it already exists. In your example, the first value is 20/04/2013 00:00:00.0
, the second one is at 20/04/2013 00:00:00.001
and the third is 20/04/2013 00:00:00.002
.
Now, the solution to your problem is to have a wider range on the X axis.
renderer.setXAxisMax(someDate.getTime());
where someDate
can be something like 21/04/2013
.
这篇关于在一天保存用户数据(在同一天 - &GT;许多用户数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!