如何消除JFreeChart时间段之间的差距 [英] How to remove gaps between a time period of JFreeChart
问题描述
我想知道如何节省时间,例如(从下午5点至上午9点)来自JFreeChart
中的时间序列.我已经尝试过了:
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.
推荐答案
此处是一个很好的例子.在此示例中,newWorkdayTimeline()
创建一个新的SegmentedTimeline
,其中包括8小时,但不包括16小时.然后,在指定的小时数过去后,它从星期一开始.然后,它链接newMondayThroughFridayTimeline()
以获得工作日9-5.
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;
}
这篇关于如何消除JFreeChart时间段之间的差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!