如何在不影响 JFreeChart 中当前时间序列的情况下绘制另一个时间序列

How to plot another timeseries without affecting current timeseries in JFreeChart

所以我有一个包含 3 个不同时间序列的折线图:

"Voltage"线表示实时数据,整个"High"和 "Low" 系列实际上是从文件中动态加载的(每当用户单击“加载”按钮时)。

这里的问题是,如果我从 CSV 文件加载整个 "High" 和 "Low" 系列,然后在实时数据到来时绘制它,它只会显示一些最终的"High" 和 "Low" 系列的点,然后我们必须等待那个时间段的实时数据到来(这是可以理解的)。

然后我解决这个问题的想法是绘制 "High" 和 "Low" 只是从 "Voltage" 系列的第一个点的时间段到最大时间段当我向 "Voltage" 系列添加一个新点时,当前日期轴的位置。

public void add(Data data) throws ParseException, CloneNotSupportedException {
    Date date = new SimpleDateFormat(PATTERN).parse(data.getDate());
    Millisecond milis = new Millisecond(date);
    timeSeries.add(milis, data.getNumber());
    Date maxDate = axis.getMaximumDate();
    Date minDate = dataset.getSeries(0).getTimePeriod(0).getStart();
    Millisecond maxMili = new Millisecond(maxDate);
    Millisecond minMili = new Millisecond(minDate);
    // highSeries and lowSeries are loaded from csv file
    TimeSeries tempHighSeries = highSeries.createCopy(minMili, maxMili);
    TimeSeries tempLowSeries = lowSeries.createCopy(minMili, maxMili);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(tempHighSeries);
    collection.addSeries(tempLowSeries);
    plot.setDataset(1, collection);
}

结果就是上图。然而,我真正想要的是这样的:

我希望用户仍然可以看到这些边缘的下一部分(当"High"和"Low"系列的下一个点不在实时数据范围内时)

有什么指点吗?

您需要解决几个问题才能获得预期的结果。假设三个 TimeSeries 具有键 "High""Low""Voltage"

  • 使用SwignWorker, as shown here在后台收集数据。

  • process() 的实现中,将新到达的值添加到 "Voltage" 并在相关时间合并 "High""Low" 的现有值.

  • tn成为这样的时间。在 tn+1,添加下一个值还为时过早,例如 "High"。相反,使用 linear interpolation, as shown here 确定位于 "High" 投影上的新点的值。每条这样的线都将以 "High" 的连续值为界,在图表中以手绘的粗蓝色显示。可以临时添加新点,在​​连续值之间更新,并在需要新值 "High".

  • 时最终替换
  • "Low"做同样的事情。

  • 您可以通过覆盖 getItemShape() 来省略临时点的形状,如图 here 所示,并根据需要返回空形状。