JFreeChartSeries 系列异常... "attempting to add an observation for the time period..."
JFreeChartSeries Series Exception... "attempting to add an observation for the time period..."
我想绘制一个 xy 图表,time/date 是我的定义域,整数是我的范围。我设法得到了我想要的图表....domain/range min/max 是它从 excel 单元格中读取的最低值和最高值,但它没有在图表,但调试后我不确定如何继续...
TimeSeries timeSeries = new TimeSeries("time");
TimeSeriesCollection timeDataSet = new TimeSeriesCollection(timeSeries);
while (rowIterator.hasNext()) {
Date date;
Number y_data = 0;
row = (XSSFRow) rowIterator.next();
XSSFCell x_col = row.getCell(0);
date = x_col.getDateCellValue();
Time t = new Time(date.getTime());
XSSFCell y_col = row.getCell(1);
y_data = y_col.getNumericCellValue();
///////PROBLEM BELOW
timeSeries.add(new Day(t), y_data); //timeSeries.addOrUpdate(new Day(t), y_data)
}
timeDataSet.addSeries(timeSeries);
我有两个选择,但都没有帮助...如果我使用 timeSeries.add() 我会收到上述错误,即使它们是完全不同的时间...是的,它们是同一天,更具体地说,某些读取的分钟数甚至相同,但秒数和毫秒数不同。如果我使用 timeSeries.addOrUpdate() 它似乎完全覆盖了每次读取并且我的 TimeSeries 变量 arraylist 只是有垃圾......这是它读取所有值后的内容,[org.jfree.data.time.TimeSeriesDataItem@40c77f1e , null, null,...] 只是更多 null..... 我知道它应该存储 xy 对因为我是 运行 另一个更简单的例子并且它有适当的对可能这是不同的因为我正在使用 TimeSeries .....我也尝试过不使用 Time 所以只是让它成为
timeSeries.addOrUpdate(new Day(date), y_date);
但同样的问题......感谢您的任何建议
这是正常的。您使用 Day JfreeChart class,这是一天的 TimePeriod,没有时间意识。
/**
* Represents a single day in the range 1-Jan-1900 to 31-Dec-9999. This class
* is immutable, which is a requirement for all {@link RegularTimePeriod}
* subclasses.
*/
public class Day extends RegularTimePeriod implements Serializable {
尝试使用更精细的 TimePeriod,例如 FixedMillisecond 或 Millisecond,您应该不会再遇到此问题。如:
timeSeries.add(new FixedMillisecond (date.getTime()), y_data);
供您参考,在时间序列中,时间段可以是以下任何一个:
Year
Quarter
Month
Week
Day
Hour
Minute
Second
Millisecond
FixedMillisecond
我想绘制一个 xy 图表,time/date 是我的定义域,整数是我的范围。我设法得到了我想要的图表....domain/range min/max 是它从 excel 单元格中读取的最低值和最高值,但它没有在图表,但调试后我不确定如何继续...
TimeSeries timeSeries = new TimeSeries("time");
TimeSeriesCollection timeDataSet = new TimeSeriesCollection(timeSeries);
while (rowIterator.hasNext()) {
Date date;
Number y_data = 0;
row = (XSSFRow) rowIterator.next();
XSSFCell x_col = row.getCell(0);
date = x_col.getDateCellValue();
Time t = new Time(date.getTime());
XSSFCell y_col = row.getCell(1);
y_data = y_col.getNumericCellValue();
///////PROBLEM BELOW
timeSeries.add(new Day(t), y_data); //timeSeries.addOrUpdate(new Day(t), y_data)
}
timeDataSet.addSeries(timeSeries);
我有两个选择,但都没有帮助...如果我使用 timeSeries.add() 我会收到上述错误,即使它们是完全不同的时间...是的,它们是同一天,更具体地说,某些读取的分钟数甚至相同,但秒数和毫秒数不同。如果我使用 timeSeries.addOrUpdate() 它似乎完全覆盖了每次读取并且我的 TimeSeries 变量 arraylist 只是有垃圾......这是它读取所有值后的内容,[org.jfree.data.time.TimeSeriesDataItem@40c77f1e , null, null,...] 只是更多 null..... 我知道它应该存储 xy 对因为我是 运行 另一个更简单的例子并且它有适当的对可能这是不同的因为我正在使用 TimeSeries .....我也尝试过不使用 Time 所以只是让它成为
timeSeries.addOrUpdate(new Day(date), y_date);
但同样的问题......感谢您的任何建议
这是正常的。您使用 Day JfreeChart class,这是一天的 TimePeriod,没有时间意识。
/**
* Represents a single day in the range 1-Jan-1900 to 31-Dec-9999. This class
* is immutable, which is a requirement for all {@link RegularTimePeriod}
* subclasses.
*/
public class Day extends RegularTimePeriod implements Serializable {
尝试使用更精细的 TimePeriod,例如 FixedMillisecond 或 Millisecond,您应该不会再遇到此问题。如:
timeSeries.add(new FixedMillisecond (date.getTime()), y_data);
供您参考,在时间序列中,时间段可以是以下任何一个:
Year
Quarter
Month
Week
Day
Hour
Minute
Second
Millisecond
FixedMillisecond