【发布时间】:2011-07-28 09:45:41
【问题描述】:
我正在尝试定义一个接口,我想在其中绘制一些外部设备接收到的值。 这些值的接收频率可以通过接口设置。当然,情节的周期应该根据用户定义的周期而变化。 于是我开始定义如下图表:
int periodMs = 200;
MilliDTSC dataset = new MilliDTSC(1,100, new MultipleOfMillisecond(periodMs));
dataset.setTimeBase(new MultipleOfMillisecond(periodMs))
dataset.addSeries(zeroSeries()),0,"Zero data") // zeroSeries returs a series with values set to 0
JFreeChart chart = createChart(dataset) // create the chart and set ranges and legends
ChartPanel panel = new ChartPanel(panel);
MilliDTSC 是以下类,建议here:
public class MilliDTSC extends DynamicTimeSeriesCollection{
public MilliDTSC(int nSeries, int nMoments, RegularTimePeriod timeSample){
super(nSeries, nMoments, timeSample);
if(timeSample instanceof Millisecond)
this.pointsInTime = new Millisecond[nMoments]
else if (timeSample instanceof MultipleOfMillisecond)
this.pointsInTime = new MultipleOfMillisecond[nMoments]
}
}
MultipleOfMillisecond 是以下类:
public class MultipleOfMilliseconds extends Millisecond{
MulitpleOfMilliseconds(int periodMs){
this.periodMs = periodMs
}
public RegularTimePeriod previous(){
RegularTimePeriod result = null;
if(getMillisecond() - periodMs >= FIRST_MILLISECOND_IN_SECOND)
result = new Millisecond((int)getMillisecond - periodMs, getSecond());
else{
Second previous = (Second)getSecond().previous();
if(previous!=null)
result = new Millisecond((int)(getMillisecond() - periodMS + LAST_MILLISECOND_IN_SECOND + 1), previous);
}
return result;
}
// similar for next()
}
我通过以下方式将样本添加到系列中:
dataset.advanceTime();
dataset.appendData(newData);
我所期望的是,一旦我将周期固定为 200 毫秒,图表就会在 X 标签上报告或多或少 5 个时间值:
00:00:00.000 00:00:05.000 00:00:10.000 00:00:15.000 00:00:20.000
我预计每个“空间”中有 25 个样本。
相反,我对每个“空间”有 25 个样本,但图表在 X 标签上报告了以下值:
00:00:00.000 00:00:00.025 00:00:00.050 00:00:00.075 00:00:00.100
似乎周期是 1 毫秒,但我添加的样本非常 200 毫秒。
我该如何解决这个问题? 如果我不清楚,请告诉我。 谢谢!!
【问题讨论】:
标签: java jfreechart