achartengine – can’t figure how to use dates as x axis – the file I save is empty

The code that deal with your file must be something like this (not compiled):

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]));
...

Hope it helps.

Leave a Comment