具有竞争条件的 JFreeChart addBin?
JFreeChart addBin with race condition?
我目前正在做一个项目,我想在其中绘制一些测量时间。为此,我使用 JFreeChart 1.0.13
。
我想用 SimpleHistogramBin
创建一个直方图,然后将数据添加到这些容器中。这是代码:
Double min = Collections.min(values);
Double max = Collections.max(values);
Double current = min;
int range = 1000;
double minimalOffset = 0.0000000001;
Double stepWidth = (max-min) / range;
SimpleHistogramDataset dataSet = new SimpleHistogramDataset("");
for (int i = 0; i <= range; i++) {
SimpleHistogramBin bin;
if (i != 0) {
bin = new SimpleHistogramBin(current + minimalOffset, current + stepWidth);
} else {
bin = new SimpleHistogramBin(current, current + stepWidth);
}
dataSet.addBin(bin);
current += stepWidth;
}
for (Double value : values) {
System.out.println(value);
dataSet.addObservation(value);
}
This crashes with Exception in thread "main" java.lang.RuntimeException: No bin.
起初我以为这是因为在 bins 中打了一个缺口造成的,但是当我开始调试时,错误并没有发生。程序 运行 通过,我得到了一个情节。然后我添加了这个:
Thread.sleep(1000);
之前
for (Double value : values) {
System.out.println(value);
dataSet.addObservation(value);
}
再一次,没有错误。
这让我想到可能存在某种竞争条件? JFreeChart 是否异步添加垃圾箱?我会很感激任何方向的提示,为什么我会得到这种行为。
谢谢
如果有人遇到同样的问题,我找到了解决方案:
我没有使用 SimpleHistorgramBin
,而是使用 HistogramBin
。这基本上将我的代码减少到几行:
HistogramDataset dataSet = new HistogramDataset();
dataSet.setType(HistogramType.FREQUENCY);
dataSet.addSeries("Hibernate", Doubles.toArray(values), 1000);
这种方法会自动创建我需要的垃圾箱,问题就迎刃而解了。
我目前正在做一个项目,我想在其中绘制一些测量时间。为此,我使用 JFreeChart 1.0.13
。
我想用 SimpleHistogramBin
创建一个直方图,然后将数据添加到这些容器中。这是代码:
Double min = Collections.min(values);
Double max = Collections.max(values);
Double current = min;
int range = 1000;
double minimalOffset = 0.0000000001;
Double stepWidth = (max-min) / range;
SimpleHistogramDataset dataSet = new SimpleHistogramDataset("");
for (int i = 0; i <= range; i++) {
SimpleHistogramBin bin;
if (i != 0) {
bin = new SimpleHistogramBin(current + minimalOffset, current + stepWidth);
} else {
bin = new SimpleHistogramBin(current, current + stepWidth);
}
dataSet.addBin(bin);
current += stepWidth;
}
for (Double value : values) {
System.out.println(value);
dataSet.addObservation(value);
}
This crashes with Exception in thread "main" java.lang.RuntimeException: No bin.
起初我以为这是因为在 bins 中打了一个缺口造成的,但是当我开始调试时,错误并没有发生。程序 运行 通过,我得到了一个情节。然后我添加了这个:
Thread.sleep(1000);
之前
for (Double value : values) {
System.out.println(value);
dataSet.addObservation(value);
}
再一次,没有错误。
这让我想到可能存在某种竞争条件? JFreeChart 是否异步添加垃圾箱?我会很感激任何方向的提示,为什么我会得到这种行为。
谢谢
如果有人遇到同样的问题,我找到了解决方案:
我没有使用 SimpleHistorgramBin
,而是使用 HistogramBin
。这基本上将我的代码减少到几行:
HistogramDataset dataSet = new HistogramDataset();
dataSet.setType(HistogramType.FREQUENCY);
dataSet.addSeries("Hibernate", Doubles.toArray(values), 1000);
这种方法会自动创建我需要的垃圾箱,问题就迎刃而解了。