如何消除JFreeChart时间段之间的差距 [英] How to remove gaps between a time period of JFreeChart

查看:97
本文介绍了如何消除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.

推荐答案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆