0

我在 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)

有任何想法吗 ?

4

2 回答 2

1

来源:_

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

于 2013-03-06T09:12:20.557 回答
1

我的猜测:你调用函数

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

例外说

Requires 'start' < 'end'

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

于 2013-03-06T09:13:14.603 回答