我有,我把投入编辑文本,并将其存储在一个列表中的活动。
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.
然后,我preSS保存按钮,从而节省了上面。
Then , I press the save button which saves the above.
第二天用户输入一些数据更多,保存等。
The next day the user enter some data more and save and so on.
我想要与x轴的日期格式和y轴的用户输入的值的情节。
I want to make a plot with x-axis date format and y axis the values the user entered.
在一个活动,我有:
...
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活动:
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));
}
读功能:
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)我收到的文件是空的(有些问题的日期,因为该方法保存和从文件中读取的作品)。
1) The file I receive is empty (some problem with the Date because the method for saving and reading from a file works).
2)在图形屏幕会出现一个白色背景(当然没有数据,因为该文件是空的),但为什么白色背景?我用的是相同的code用于其他用途,我没有收到whitebackground。
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)我不知道如何使用我使用清单以x axis.Should日期?名单? 。
3) I am not sure how to use Dates in x axis.Should I use List ? List ? .
------------------------更新---------------------- -----------------------------------
------------------------UPDATE---------------------------------------------------------
好了,终于来了!(用户'丹'的建议后)
Ok ,finally!(After user 'Dan' suggestion)
我用 ChartFactory.getTimeChartView(这一点,数据集,mRenderer,DD / MM / YYYY);
而不是 ChartFactory.getLineChartIntent(背景下,数据集,mRenderer,DD / MM / YYYY);
和你不需要使用字符串列表,只是日期列表
and you don't need to use String List , just Date List
在code,它处理你的文件必须是这样的(不编译):
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.