例外:需要'开始'< '结束'

时间:2013-03-06 09:08:49

标签: java jfreechart

我在main中的代码如下所示:

ArrayList<Integer> temper = new ArrayList<>();
     ArrayList<Float> time = new ArrayList<>();
     while(rs.next()){
         time.add(rs.getFloat("Time_ms"));
         temper.add(rs.getInt("VarValue"));                
     }
     timemax = Collections.max(time);
     timemin = Collections.min(time);         
     tempermax = Collections.max(temper);
     tempermin = Collections.min(temper);

我也有这个创建图表的类:

public NormalDistributionDemo(final String title) {

    super(title);
    Function2D normal = new NormalDistributionFunction2D(2, 8);
    XYDataset dataset = DatasetUtilities.sampleFunction2D(normal,0, 5, 10, "Normal");
    final JFreeChart chart = ChartFactory.createXYLineChart(
        "AS Hellas Database",
        "Date", 
        "Temperature", 
        dataset,
        PlotOrientation.VERTICAL,
        true,
        true,
        false
    );
}

此代码工作正常但我想从我的数据库中提取值并将它们插入x,y轴。

我这样做:

Function2D normal = new NormalDistributionFunction2D(tempermin, tempermax);
XYDataset dataset = DatasetUtilities.sampleFunction2D(normal,timemin, timemax,     10,"Normal");

我收到了这个错误:

Exception in thread "main" java.lang.IllegalArgumentException: Requires 'start' < 'end'.
at     org.jfree.data.general.DatasetUtilities.sampleFunction2DToSeries(DatasetUtilities.java:542)
at     org.jfree.data.general.DatasetUtilities.sampleFunction2D(DatasetUtilities.java:511)
at org.jfree.chart.demo.NormalDistributionDemo.<init>    (NormalDistributionDemo.java:80)
at org.jfree.chart.demo.NormalDistributionDemo.main(NormalDistributionDemo.java:71)

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

来自sources

public static XYSeries sampleFunction2DToSeries(Function2D f,
        double start, double end, int samples, Comparable seriesKey) {

    // some code

    if (start >= end) {
        throw new IllegalArgumentException("Requires 'start' < 'end'.");
    }

    // some code
}

这意味着,您timemin传递的次数少于或等于timemax

答案 1 :(得分:1)

我的猜测:你调用函数

DatasetUtilities.sampleFunction2D(normal,timemin, timemax, 10,"Normal");

例外说

Requires 'start' < 'end'

所以你可能有timemin == timemax。原因可能是ArrayList<Float> time只有一个值,或者它的所有值都相同。