将JFreeChart TimeSeries限制为营业时间

编程入门 行业动态 更新时间:2024-10-26 02:32:48
本文介绍了将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 }

推荐答案

您也许可以使用 DateAxis 和自定义 Timeline . 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限制为营业时间

本文发布于:2023-10-23 01:42:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:营业时间   JFreeChart   TimeSeries

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!