android – achartengine – 无法计算如何使用日期作为x轴 – 我保存的文件为空

android – achartengine – 无法计算如何使用日期作为x轴 – 我保存的文件为空,第1张

概述我有一个活动,我从编辑文本中获取输入并将其存储在列表中. 我还在列表中存储当前日期. 然后,按下保存按钮,保存上面的内容. 第二天,用户输入更多数据并保存,依此类推. 我想用x轴日期格式制作一个图,用y轴制作用户输入的值. 在一项活动中,我有: ...String filename = "data.csv"; List<Double> mydata=new ArrayList<Doubl 我有一个活动,我从编辑文本中获取输入并将其存储在列表中.

我还在列表中存储当前日期.

然后,按下保存按钮,保存上面的内容.

第二天,用户输入更多数据并保存,依此类推.

我想用x轴日期格式制作一个图,用y轴制作用户输入的值.

在一项活动中,我有:

...String filename = "data.csv";    List<Double> mydata=new ArrayList<Double>();List<Date> mydate=new ArrayList<Date>();....value=(EditText) findVIEwByID(R.ID.enter_data);...switch (v.getID()){        case R.ID.savebtn:            savefunc();            break;        case R.ID.graphicsbtn:             Intent i = new Intent();                    i.setClassname(this,lineGraph.class.getname());                             this.startActivity(i);              break;   public voID savefunc(){    SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");     Date d=new Date();    try{     d=thedate.parse(filename);    mydate.add(d);    }    catch  (ParseException e){        // Todo auto-generated catch block        e.printstacktrace();    }    double thedata=Double.parseDouble(value.getText().toString().trim());    mydata.add(thedata);..BuffereDWriter bw = new BuffereDWriter(new OutputStreamWriter(fos));    for (int i=0;i<mydate.size();i++){       bw.write(mydate.get(i)+","+mydata.get(i)+"\n");   ...

在lineGraph活动中:

public class lineGraph extends Activity {    private static List<Date> date = new ArrayList<Date>();private static List<Double> data = new ArrayList<Double>();    public Intent getIntent(Context context){           readfunc();      TimeSerIEs serIEs = new TimeSerIEs("Showing data");    for (int i=0;i<date.size();i++){            serIEs.add(date.get(i),data.get(i));        }

读取功能:

public voID readfunc(){    SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");     Date d=new Date();    try{     d=thedate.parse(filename);    }    catch..     BufferedReader br = new BufferedReader(new inputStreamReader(fis));         do {             s = br.readline();                  if (s != null ){                 String[] splitline = s.split(",");                 date.add(d);//Double.parseDouble(splitline[0]));                 data.add(Double.parseDouble(splitline[1]));

我有这些问题:

1)我收到的文件是空的(Date的一些问题,因为保存和读取文件的方法有效).

2)在图形屏幕出现一个白色背景(当然没有数据,因为文件是空的),但为什么是白色背景?我使用相同的代码用于其他目的,我没有收到白色背景.

3)我不知道如何在x轴上使用日期.我应该使用List吗?清单? .

———————— UPDATE ————————- ——————————–

好的,终于!(在用户’丹’建议之后)

我使用ChartFactory.getTimeChartVIEw(this,dataset,mRenderer,“dd / MM / yyyy”);

而不是ChartFactory.getlineChartIntent(context,“dd / MM / yyyy”);

并且您不需要使用字符串列表,只需使用日期列表

解决方法 处理您文件的代码必须是这样的(未编译):

public voID savefunc(){    List<String> myDate = new ArrayList<String>(); //To store the formatted dates    SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");     Date d=new Date(); //the current date    String sd = thedate.format(d); // sd contains "16/04/2013",the formatted date    myDate.add(sd);    double thedata=Double.parseDouble(value.getText().toString().trim());    mydata.add(thedata);    ...    BuffereDWriter bw = new BuffereDWriter(new OutputStreamWriter(fos));    for (int i=0;i<mydate.size();i++){       bw.write(mydate.get(i)+","+mydata.get(i)+"\n");    }}public voID readfunc(){    SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");     Date d;    BufferedReader br = new BufferedReader(new inputStreamReader(fis));    do {        s = br.readline();             if (s != null ){            String[] splitline = s.split(","); //first substring is the formatted date            date.add(thedate.parse(splitline[0])); //do something with exception            data.add(Double.parseDouble(splitline[1]));...

希望能帮助到你.

总结

以上是内存溢出为你收集整理的android – achartengine – 无法计算如何使用日期作为x轴 – 我保存的文件为空全部内容,希望文章能够帮你解决android – achartengine – 无法计算如何使用日期作为x轴 – 我保存的文件为空所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1121452.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存