如何消除 JFreeChart 时间段之间的差距

How to remove gaps between a time period of JFreeChart

我想知道如何删除时间,例如(下午 5 点到早上 9 点)来自 JFreeChart 的时间序列。我试过这个:

SegmentedTimeline baseTimeLine = new SegmentedTimeline(
    SegmentedTimeline.DAY_SEGMENT_SIZE,24,1);

但是,我认为这不是删除时间段所需要的。

SegmentedTimeline.newFifteenMinuteTimeline(), seen here 是一个很好的起点。在此示例中,newWorkdayTimeline() 创建了一个新的 SegmentedTimeline,其中包括 8 小时但不包括 16 小时。然后在规定的小时数过去后于星期一开始。然后它链接一个 newMondayThroughFridayTimeline() 以获得工作日,9-5.

public static SegmentedTimeline newWorkdayTimeline() {
    SegmentedTimeline timeline = new SegmentedTimeline(
        SegmentedTimeline.HOUR_SEGMENT_SIZE, 8, 16);
    timeline.setStartTime(SegmentedTimeline.firstMondayAfter1900()
        + 8 * timeline.getSegmentSize());
    timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
    return timeline;
}

从这个 example 开始,我绘制了一周的随机小时数据。放大域轴以查看效果。我已经包含了一个连续的数据集,以便更容易看到分段边界。

private static final int N = 168; // a week
…
private static JFreeChart buildChart(
    …
    XYPlot plot = chart.getXYPlot();
    ((DateAxis) plot.getDomainAxis()).setTimeline(newWorkdayTimeline());
    …
    return chart;
}