How to display only “last 24 hours” from a “last 72 hours” JFreeChart TimeSeries

て烟熏妆下的殇ゞ 提交于 2019-12-02 01:38:35

Instead of discarding old data, as suggested here, it looks like you want to display a contiguous subset of the data, as if looking through a window. While SlidingCategoryDataset provides this feature for a CategoryDataset, there is no built-in solution for an XYDataset. SlidingXYDataset, seen here, maybe an alternative. In the variation of SliderDemo2 illustrated below, I've added three days of data to a single series with a one day window. I've retained the slider for easy review of earlier values.

static final int COUNT = 3 * 24 * 60;
public static final int WINDOW = 24 * 60;
public static final int FIRST = 2 * 24 * 60;
…
this.slider.setValue(FIRST);

As an aside, note that some classes have moved since the patch was submitted:

import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

Can't I just use setMaximumItemAge()?

Not in isolation; addOrUpdate(), et al., calls removeAgedItems(false) before notifying listeners.

I am using Second.

Threes days of Second data, e.g., would imply setMaximumItemAge(3 * 24 * 60 * 60).

A sliding window might not be available to me since I am saving the chart as a JPEG.

You can pass the desired firstItemIndex as a parameter to the SlidingXYDataset constructor; you can update the index later via setFirstItemIndex() if needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!