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

I have an activity where I take the input from edit text and store it in an list.

I also store in list the current date.

Then , I press the save button which saves the above.

The next day the user enter some data more and save and so on.

I want to make a plot with x-axis date format and y axis the values the user entered.

In one activity I have:

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

In the LineGraph Activity:

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

    }

The read function:

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

I have these problems:

1) The file I receive is empty (some problem with the Date because the method for saving and reading from a file works).

2) At the graph screen appears a white background (of course no data because the file is empty) ,but why white background?I use the same code for other purposes and I don't receive a whitebackground.

3) I am not sure how to use Dates in x axis.Should I use List ? List ? .

------------------------UPDATE---------------------------------------------------------

Ok ,finally!(After user 'Dan' suggestion)

I used ChartFactory.getTimeChartView(this, dataset, mRenderer,"dd/MM/yyyy");

instead of ChartFactory.getLineChartIntent(context, dataset, mRenderer,"dd/MM/yyyy");

and you don't need to use String List , just Date List

Answers


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.


Need Your Help

How to disable WebCam diode programatically

c# c++ programming-languages winforms-interop

In my laptop (Dell) strong blue diode light while WebCam use is annoying me.

Counting number of views for a page ignoring search engines?

search-engine website-metrics

I notice that Stack Overflow has a views count for each question and that these view numbers are fairly low and accurate.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.