Java JFreeChartSeries系列异常&引用;正在尝试为时间段添加观察结果…“;

Java JFreeChartSeries系列异常&引用;正在尝试为时间段添加观察结果…“;,java,excel,apache-poi,jfreechart,Java,Excel,Apache Poi,Jfreechart,我想绘制一个xy图表,时间/日期是我的域,整数是我的范围。我设法得到了我想要的图形…域/范围最小值/最大值是从excel单元格中读取的最低值和最高值,但它没有在图表上绘制任何内容,但调试后我不确定如何继续 TimeSeries timeSeries = new TimeSeries("time"); TimeSeriesCollection timeDataSet = new TimeSeriesCollection(timeSeries); while (rowIterator.h

我想绘制一个xy图表,时间/日期是我的域,整数是我的范围。我设法得到了我想要的图形…域/范围最小值/最大值是从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…..我也尝试过不使用时间,所以就这样吧

 timeSeries.addOrUpdate(new Day(date), y_date);

但同样的问题……谢谢你的建议,这很正常。您使用Day JfreeChart类,它是一个不知道时间的日期时段

/**
* 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 {
尝试使用更精细的时间段,如FixedMill Second或Mill Second,您应该不会再有问题了。例如:

timeSeries.add(new FixedMillisecond (date.getTime()), y_data); 
供您参考,在timeseries中,时间段可以是以下任一时间段:

Year 
Quarter 
Month 
Week 
Day 
Hour 
Minute 
Second 
Millisecond 
FixedMillisecond 

这就是timeSeries。添加(新的第二个(日期),y_数据)。。。。我猜测是因为它们是不同的秒数,但如果两次读取的秒数相同,我会遇到相同的问题……对吗?@curiousmind1995确切地说,如果表示值(y)的周期(x)小于1秒,则必须选择小于1秒的周期。否则,就不可能在图表中区分它们。