How to display only quot;last 24 hoursquot; from a quot;last 72 hoursquot; JFreeChart TimeSeries(如何仅显示“过去 24 小时?从“过去 72 小时开始JFreeChart 时间序列)
问题描述
我编写了这两行代码来使用 XYDataset
创建图表:
final XYDataset dataset = new TimeSeriesCollection(myInfo.getSeries());JFreeChart timechart = ChartFactory.createTimeSeriesChart(myInfo.getName()+ " CPU (last 72h)", "", "CPU %", dataset, false, false, false);
这些线条创建了这个漂亮的过去 72 小时"图表:
这就是我添加信息来构建这个图表的方式(这段代码可以运行多次):
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");日期日期 = simpleDateFormat.parse(dateAsStringToParse);秒秒 = 新秒(日期);myInfo.getSeries().addOrUpdate(second, maxValue);//maxValue 是一个整数
我想要一个(看似)简单的更改——将其删减"到最后 24 小时.我的意思是在图表中只看到最近的 24 小时,就像这样(图中是我使用相同技术制作的不同图表,但信息仅存在于最近 24 小时):
我查看了 API 并找不到合适的答案,因为我相信这应该有一些聪明而简单的解决方案.
而不是丢弃旧数据,建议
顺便说一句,请注意,自从提交补丁后,一些类已经移动:
import org.jfree.ui.ApplicationFrame;导入 org.jfree.ui.RefineryUtilities;
<块引用>
我不能只使用 setMaximumItemAge()
吗?
不是孤立的;addOrUpdate()
,et al.,在通知侦听器之前调用 removeAgedItems(false)
.
我正在使用 Second
.
Second
数据的三天,例如,将暗示 setMaximumItemAge(3 * 24 * 60 * 60)
.
我可能无法使用滑动窗口,因为我将图表保存为 JPEG.
您可以将所需的 firstItemIndex
作为参数传递给 SlidingXYDataset
构造函数;如果需要,您可以稍后通过 setFirstItemIndex()
更新索引.
I wrote these 2 lines of code to create a chart using an XYDataset
:
final XYDataset dataset = new TimeSeriesCollection(myInfo.getSeries());
JFreeChart timechart = ChartFactory.createTimeSeriesChart(myInfo.getName()
+ " CPU (last 72h)", "", "CPU %", dataset, false, false, false);
These lines created this nice "last 72h" chart:
This is how I added the information to build this chart (this piece of code can run multiple times):
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
Date date = simpleDateFormat.parse(dateAsStringToParse);
Second second = new Second(date);
myInfo.getSeries().addOrUpdate(second, maxValue); // maxValue is an Integer
I want a (seemingly) simple alteration—to "cut" this only to the last 24 hours. I mean to see only the most "recent" 24 hours in the graph, like so (in the picture is a different chart I made using the same technique, but the information exists only for the last 24hrs):
I have looked through the API and could not find an appropriate answer, as I believe this should have some clever but simple solution.
Instead of discarding old data, as suggested here, it looks like you want to display a contiguous subset of the data, as if looking through a window. While SlidingCategoryDataset
provides this feature for a CategoryDataset
, there is no built-in solution for an XYDataset
. SlidingXYDataset
, seen here, maybe an alternative. In the variation of SliderDemo2
illustrated below, I've added three days of data to a single series with a one day window. I've retained the slider for easy review of earlier values.
static final int COUNT = 3 * 24 * 60;
public static final int WINDOW = 24 * 60;
public static final int FIRST = 2 * 24 * 60;
…
this.slider.setValue(FIRST);
As an aside, note that some classes have moved since the patch was submitted:
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
Can't I just use
setMaximumItemAge()
?
Not in isolation; addOrUpdate()
, et al., calls removeAgedItems(false)
before notifying listeners.
I am using
Second
.
Threes days of Second
data, e.g., would imply setMaximumItemAge(3 * 24 * 60 * 60)
.
A sliding window might not be available to me since I am saving the chart as a JPEG.
You can pass the desired firstItemIndex
as a parameter to the SlidingXYDataset
constructor; you can update the index later via setFirstItemIndex()
if needed.
这篇关于如何仅显示“过去 24 小时"?从“过去 72 小时"开始JFreeChart 时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何仅显示“过去 24 小时"?从“过去 72 小时
基础教程推荐
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01