TimeSeries:如何渲染线下的填充(或者,看起来是面积图)

发布于 2024-12-08 02:36:25 字数 260 浏览 0 评论 0原文

我正在绘制随时间变化的 CPU 平均负载图(5 秒间隔)。传统上,这是作为实心填充面积图而不是单个浮动线来完成的,例如...

在此处输入图像描述

这似乎是一个非常简单的请求,但我一直无法找到解决方案。

我剩下的一个途径是对默认渲染器进行子类化..但我一直认为必须有更简单的东西。

你的线索&非常欢迎其他指点。

M。

I am graphing CPU load average over time (5s intervals). Traditionally this is done as a solid filled area graph rather than a single floating line, for example ...

enter image description here

It seems a very simple request, but I've not been able to find the solution.

My one remaining avenue is to subclass the default renderer .. but I keep thinking there has to be something simpler.

Your clues & other pointers would be most welcome.

M.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你对谁都笑 2024-12-15 02:36:25

也许我来晚了一点,但我有一个可能的解决方案给你。 jfreechart 允许制作这些图表。
由于您需要 CPU 负载图表,因此最好的图表类型是 TimeSeriesChart。用于此图表的最佳数据集是 TimeSeriesCollection。在图中,您的时间序列集合包含 2 个时间序列。

主要解决方案是使用 2 个渲染器和 2 个独立的数据集。第一个渲染(显示实心字段区域)应该是 XYAreaRenderer。第二个(显示水平线)应该是 XYLineAndShapeRenderer。
下面是我们如何使用它的示例:

JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, 
                       axisXTitle, axisYTitle, dataset, true, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
XYAreaRenderer renderer = new XYAreaRenderer();
renderer.setSeriesVisible(0, true);
renderer.setSeriesVisible(1, false);
plot.setRenderer(0, renderer);

// this part is important, we should create 
// the new dataset object exactly the same as original
TimeSeriesCollection newDataset = null;

if (plot.getDataset(0) instanceof TimeSeriesCollection) {
    newDataset = (TimeSeriesCollection) 
                 ((TimeSeriesCollection) plot.getDataset()).clone();
}
plot.setDataset(1, newDataset);

// add new XYLineAndShapeRenderer to display capacity
XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(true, false);
lineAndShapeRenderer.setSeriesVisible(0, false);
lineAndShapeRenderer.setSeriesVisible(1, true);
plot.setRenderer(1, lineAndShapeRenderer);

当然,您可以根据需要自定义这些渲染器(例如设置自定义颜色等)。请在此界面查看更多信息: XYItemRenderer
此外,您还可以自定义图表(图)。请看这里:绘图

Maybe I am a little bit late, but I have a possible solution for you. jfreechart allows to make these charts.
Since you need for CPU load chart, the best type of chart is TimeSeriesChart. The best dataset using for this chart is TimeSeriesCollection. In the picture your timeseries collection contains 2 timeseries.

The main solution is to use 2 renderers with 2 separate datasets. The first render (that displays solid field area) should be XYAreaRenderer. The second (that displays horizontal line) should be XYLineAndShapeRenderer.
Here is an example how we can use it:

JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, 
                       axisXTitle, axisYTitle, dataset, true, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
XYAreaRenderer renderer = new XYAreaRenderer();
renderer.setSeriesVisible(0, true);
renderer.setSeriesVisible(1, false);
plot.setRenderer(0, renderer);

// this part is important, we should create 
// the new dataset object exactly the same as original
TimeSeriesCollection newDataset = null;

if (plot.getDataset(0) instanceof TimeSeriesCollection) {
    newDataset = (TimeSeriesCollection) 
                 ((TimeSeriesCollection) plot.getDataset()).clone();
}
plot.setDataset(1, newDataset);

// add new XYLineAndShapeRenderer to display capacity
XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(true, false);
lineAndShapeRenderer.setSeriesVisible(0, false);
lineAndShapeRenderer.setSeriesVisible(1, true);
plot.setRenderer(1, lineAndShapeRenderer);

Of course you can customize these renderers as you want (such as set custom colors and so on). Please, see more information at this interface: XYItemRenderer.
Also, you can customize the chart (plot). Look here: Plot.

拍不死你 2024-12-15 02:36:25

您可能正在寻找 org.jfree.chart.renderer.AreaRenderer 面积图下的示例演示面积图。或者,XYBarRenderer制作了一个很好的直方图。

You are probably looking for an org.jfree.chart.renderer.AreaRenderer. Several examles are shown in the sample demo under Area Charts. Alternatively, an XYBarRenderer makes a nice histogram.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文