问题描述
(我用固定保存和加载一些问题对我的previous公告)
(I fixed some issues with saving and loading regarding my previous posts)
我节省了一些数据(MYDATA)及日期为字符串(dates_Strings)。
I am saving some data (mydata) and the date as strings (dates_Strings).
在图中的活动我加载数据和dates.And我转换dates_Strings为日期,以便使用它们中的情节。
In graph activity I load data and dates.And I convert dates_Strings to dates in order to use them in the plot.
现在,在输入一些数据,例如1,2,3,在13年10月5日我收到如下图所示。
Now , while entering some data for example "1","2","3" in 10/05/13 I am getting the following image.
所有好到现在。
如果我尝试在另一日期(13/05/13)我得到这个图像输入更多的数据(3,4,7)。
If I try to enter some more data ("3,4,7") in another date (13/05/13) I am getting this image.
日期叠加。
在MainActivity:
The MainActivity :
在code:
//copy the dates_asString to date (Dates) in order to use them in TimeSeries
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy",Locale.US);
Date convertedDate;
try{
for (int k=0;k<mydata.size();k++){
convertedDate = formatter.parse(dates_Strings.get(k));
date.clear();
date.add(convertedDate);
Log.d("line","convertedDate :"+convertedDate);
}
}catch ...
//TimeSeries series = new TimeSeries("Showing data");
//for (int i=0;i<mydata.size();i++){
// series.add(i,mydata.get(i));
//}
XYSeries series = new XYSeries("Showing data");
for (int i=0;i<mydata.size();i++){
series.add(i,mydata.get(i));
}
XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer renderer =new XYSeriesRenderer();
renderer.setColor(Color.YELLOW);
...
XYMultipleSeriesRenderer mRenderer =new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
...
mRenderer.setXRoundedLabels(false);
mRenderer.setXLabels(0);
//mRenderer.setXAxisMax(mydata.size());
for (int i=0;i<mydata.size();i++){
mRenderer.addXTextLabel(i,dates_Strings.get(i));
}
我把setXAxisMax值14/05/2013,我在10/05和13/05例如输入的数据。
I put in setXAxisMax the value 14/05/2013 and I entered data in 10/05 and 13/05 for example.
当我使用setXAxisMin的情节完全是空的。
When I use setXAxisMin the plot is completely empty.
如果我不使用setXAxisMax出现另一个奇怪的问题。余输入1和2作为数据,但图中显示的2(第二数据)的两点。
Another weird problem occurs if I don't use setXAxisMax . I enter "1" and "2" as data but the plot shows the "2" (second data) in two points. :
------------------更新---------------------------- ------------
------------------UPDATE----------------------------------------
好吧,我想将数据保存在文件中时问题所在。
Ok, I think the problem lies during saving the data in the file.
用户输入一些数据(MYDATA)在一个EditText字段,然后presses保存按钮一起保存的数据与当前的日期。
The user enters some data (mydata) in an edittext field and then presses the save button which saves that data together with the current date.
例如,用户输入1和presses保存。
For example , user enters "1" and presses "save".
用户输入2和presses保存。
user enters "2" and presses "save".
所以,我有数据1和2在同一日期(13年8月5日)。
So, I have data "1" and "2" in the same date (08/05/13).
我想保存的时间的一个实例(因为它是在同一日期),以便有一个点(日期)在X轴和2点(1和2)在y轴上。
I want to save one instance of the date (because it is the same date) in order to have one point (date) in x axis and 2 points (1 and 2) in y axis.
我保存为:
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
for (int i=0;i<mydata.size();i++){
bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
}
我想喜欢某事:
I thought sth like:
for (int i=1;i<mydata.size();i++){
bw.write(mydata.get(i)+",");
while (!(dates_Strings.get(i).equals(dates_Strings.get(i-1))))
bw.write(dates_Strings.get(i)+"\n");
}
但它仅保存最后输入的数据。
but it saves only the last entered data..
推荐答案
这看起来像的时间序列
错误的用法。您调用 series.add(我的东西)
,其中的东西
是 mydata.get(我)
在code。这意味着,该方法添加(双X,双Y)
继承了时间序列
从 XYSeries
被调用,所以 X
之间 0
您的案件范围和 mydata.size() - 1
This looks like a wrong usage of the TimeSeries
. You are calling series.add(i, something)
where something
is mydata.get(i)
in your code. This means that the method add(double x, double y)
inherited by TimeSeries
from XYSeries
is called, so x
in your case ranges between 0
and mydata.size() - 1
.
只要确保你正确地调用添加(日期X,双值)
方法时间序列
。
Just make sure you are correctly calling the add(Date x, double value)
method in TimeSeries
.
这篇关于日期在X轴重叠 - 图显示最后输入数据的2倍(当不使用setXAxisMax)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!