Note that there are some explanatory texts on larger screens.

plurals
  1. POachartengine - can't figure how to use dates as x axis - the file I save is empty
    primarykey
    data
    text
    <p>I have an activity where I take the input from edit text and store it in an list.</p> <p>I also store in list the current date.</p> <p>Then , I press the save button which saves the above.</p> <p>The next day the user enter some data more and save and so on.</p> <p>I want to make a plot with x-axis date format and y axis the values the user entered.</p> <p>In one activity I have:</p> <pre><code>... String filename = "data.csv"; List&lt;Double&gt; mydata=new ArrayList&lt;Double&gt;(); List&lt;Date&gt; mydate=new ArrayList&lt;Date&gt;(); ....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&lt;mydate.size();i++){ bw.write(mydate.get(i)+","+mydata.get(i)+"\n"); ... </code></pre> <p>In the LineGraph Activity:</p> <pre><code>public class LineGraph extends Activity { private static List&lt;Date&gt; date = new ArrayList&lt;Date&gt;(); private static List&lt;Double&gt; data = new ArrayList&lt;Double&gt;(); public Intent getIntent(Context context){ readfunc(); TimeSeries series = new TimeSeries("Showing data"); for (int i=0;i&lt;date.size();i++){ series.add(date.get(i),data.get(i)); } </code></pre> <p>The read function:</p> <pre><code>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])); </code></pre> <p>I have these problems:</p> <p>1) The file I receive is empty (some problem with the Date because the method for saving and reading from a file works).</p> <p>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.</p> <p>3) I am not sure how to use Dates in x axis.Should I use List ? List ? . </p> <p>------------------------UPDATE---------------------------------------------------------</p> <p>Ok ,finally!(After user 'Dan' suggestion)</p> <p>I used <code>ChartFactory.getTimeChartView(this, dataset, mRenderer,"dd/MM/yyyy");</code></p> <p>instead of <code>ChartFactory.getLineChartIntent(context, dataset, mRenderer,"dd/MM/yyyy");</code> </p> <p>and you don't need to use String List , just Date List</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload