在一天内保存用户数据(同一天 - >许多用户数据)

Geo*_*rge 6 java android achartengine

我有一个应用程序,用户在edittext中输入数据并按下保存按钮.

通过按"保存",我在文件中保存用户数据(在一列中)和当前日期(在另一列中).

然后,我按下另一个按钮并绘制图表(使用achartengine)日期(x轴)数据(y轴).

因此,在一天内输入数据会导致保存,例如:"1"(用户数据) - > 20/4/2013,"2" - > 20/4/2013,"3" - > 20/4/2013 .

在情节中,我在y轴上有3个点(ok),在x轴上有3个点(不是ok).

我想在x轴上有一个点,因为在同一天输入的数据.

我保存数据:

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");
              }
              ...
Run Code Online (Sandbox Code Playgroud)

如何在一天内保存用户数据?

也许有人检查一下: Date d=new Date(); ?检查是否是同一天.

或者在这里: bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");

但我无法想象.

例如,我在日期"20/4/2013"​​中输入数据"1","2","3".

这就是我现在使用我的代码得到的: 这就是我现在得到的http://i35.tinypic.com/2rmsck5.png

但是我需要如下图:在同一天输入的数据应该放在一起:: 这就是我想要的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));
    }
Run Code Online (Sandbox Code Playgroud)

Dan*_* D. 1

这确实是一个 AChartEngine 问题。过去内部模型保留在ArrayLists中,这些问题并不存在。在某个时候,社区努力让 AChartEngine 在处理大量数据点时速度更快。那时,模型开始使用 aMap而不是ArrayList。此实现防止多次添加相同的 X 值。然而,为了解决这个问题,我向 X 添加一个非常小的值(如果它已经存在)。在您的示例中,第一个值是20/04/2013 00:00:00.0,第二个值是 at 20/04/2013 00:00:00.001,第三个值是20/04/2013 00:00:00.002

现在,问题的解决方案是在 X 轴上拥有更宽的范围。

renderer.setXAxisMax(someDate.getTime());
Run Code Online (Sandbox Code Playgroud)

哪里someDate可以是类似的东西21/04/2013