How to remove gaps between a time period of JFreeChart

我怕爱的太早我们不能终老 提交于 2019-12-11 10:55:25

问题


I was wondering how to remove times e.g. (5pm to 9am) from a time series in JFreeChart. I have tried this:

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

However, I don't think this is what is needed to remove time periods.


回答1:


SegmentedTimeline.newFifteenMinuteTimeline(), seen here, is a good example from which to start. In this example, newWorkdayTimeline() creates a new SegmentedTimeline that includes 8 hours and excludes 16 hours. It then starts on Monday after the prescribed number of hours have passed. It then chains a newMondayThroughFridayTimeline() to get weekdays, 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;
}

Starting form this example, I plotted a week of random hourly data. Zoom in on the domain axis to see the effect. I've included a continuous dataset to make it easier to see the segment borders.

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



来源:https://stackoverflow.com/questions/45919485/how-to-remove-gaps-between-a-time-period-of-jfreechart

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