将JFreeChart TimeSeries限制为营业时间 [英] Limit JFreeChart TimeSeries to Business Hours

查看:70
本文介绍了将JFreeChart TimeSeries限制为营业时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天内绘制一个图表,其数据集具有24小时数据,但仅在M-F,上午7点至下午5点之间有效.如果使用下面的代码设置时间序列,则会得到一个图表,其中包含每周7天,每天24小时的所有时间.是有道理的,但不适用于我的用例.

Rendering a chart over several days, with a dataset that has 24 hour data, but it's only useful during M-F, 7AM to 5PM. If I setup a time series with the code below, I get a chart that contains all 24 hours, 7 days a week. Makes sense, but not for my use case.

是否可以定义时间序列显示的间隔?还是我需要使用其他图表类型并尝试将我的数据调整为常规周期?我希望后者不是,尽管我接收的数据通常间隔30秒,但很容易会有差距.

Is there a way to define what interval the time series displays? Or do I need to use a different chart type and attempt to fit my data into regular periods? I hope not the latter, while the data I receive is usually in 30 second intervals, there can easily be gaps.

发布带有图表的动态UI来从服务器动态查询数据几乎是不可能的,但是下面的一些要点让我对正在使用的图表类型有所了解.

It's pretty impossible to post an SSCE of a working UI with a chart dynamically asking for data from a server, but some highlights are below to get an idea of the chart types I'm using.

一些plot.add,CombinedDomainXY,索引0代码可能看起来很奇怪.我有三个共享时间值的子图,这里将其简化为一个,以使其简短.我假设有一种方法可以完成我需要做的一个绘图,这将适用于具有多个子图的图表.

Some of the plot.add, CombinedDomainXY, index 0 code may seem strange. I have three subplots with the shared time values, I've pared it down to one here to keep it short. I assume there is a way to do what I need for one plot it would work for a chart with multiple subplots.

public ChartPanel extends JPanel
{
    private final MyDataset _myDataset = new MyDataset();
    private final XYPlot _myPlot = new XYPlot();
    _chartPanel = new ChartPanel( createChart() );
    private JFreeChart createChart()
    {
            CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
                    timeAxis );
            plot.setGap( 10.0 );
            plot.setDomainPannable( true );

            plot.setDataset( index, dataset );
            NumberAxis axis = new NumberAxis();

            axis.setAutoRangeIncludesZero( false );
            plot.setRangeAxis( 0, axis );
            plot.setRangeAxisLocation( 0, axisLocation );
            plot.setRenderer( 0, new StandardXYItemRenderer() );
            plot.mapDatasetToRangeAxis( 0, index );

            // add the subplots...
            plot.add( _myPlot, 1 );
    }
}
public class MyDataset implements XYDataset
{
    @Override
    public double getYValue( int series, int item )
    {
        return getMyData(item);
    }
    @Override
    public double getXValue( int series, int item )
    {
        return _bars.get( item ).DateTime.toInstant().toEpochMilli();
    }
    //other basic overloaded methods left out for brevity
}

推荐答案

您也许可以使用 SegmentedTimeline 此处进行了检查,是一个具体的实现;尽管已弃用,但它可以作为指南.根据此示例,您的概念newWorkdayTimeline()可能看起来像这样:

You may be able to use a DateAxis with a custom Timeline. SegmentedTimeline, examined here, is a concrete implementation; although deprecated, it may serve as a guide. Based on this example, your notional newWorkdayTimeline() might look something like this:

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

示例说明了减轻您遇到的任何渲染瑕疵的一种方法.

This example illustrates one way to mitigate any rendering artifacts you encounter.

这篇关于将JFreeChart TimeSeries限制为营业时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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