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

百般思念 提交于 2019-11-27 02:18:32

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.

Kiran

for dynamic plots use GraphicalView rather then intent::

 public GraphicalView mChartView;

creat a xml::

<RelativeLayout 
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    android:id="@+id/graph"
    android:layout_width="fill_parent"
    android:layout_height="145dip" >

  </LinearLayout>
</RelativeLayout> 

then in ur code :

 LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
 mChartView = ChartFactory.mChartView = ChartFactory.getLineChartView(getBaseContext(), dataset, renderer)
 layout.addView(mChartView); 
  • After entering values you read from edit text fields right:

  • then you are passing the new values to add in respective arraylists

  • then you should call the code for linegraph again after adding new values and remember to clear series before reading arraylists (ie. dataset.clear();) ie. when line code function starts at beginning add dataset.clear(); because if u dont clear data will overlap and may through exception or line may look thick at old data ...

then call mChartView.repaint(); to refresh graph

these links too ll help u link1 link2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!