帮助JFreeChart覆盖 [英] Help with JFreeChart overlay

查看:97
本文介绍了帮助JFreeChart覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用JFreeChart重叠图形时遇到问题.我正在使用JFreeChart 1.0.13.我想做的事情似乎在JFreeChart的早期版本中更容易实现?

I'm having an issue with a JFreeChart overlaid graph. I'm using JFreeChart 1.0.13. What I am trying to do seems like it was easier to do in earlier versions of JFreeChart?

该图显示了折线图和条形图.折线图在Y轴上绘制的数据范围在0-100范围内,条形图的轴在0-5范围内.

The graph shows a line chart and a bar chart. The data range plotted by the line chart for the Y axis is in the 0-100 range, and the axis for the bar chart is in the 0-5 range.

分别地,当我布置每张图表并将其绘制时,它们看起来很棒.这是一个示例:

Individually, when I lay out each chart and paint it, they look great. Here's an example:

条形图 折线图

但是,当我将它们叠加时,条形图会被缩小以使其看起来非常无用……大概是因为两个数据集的比例差异很大.

But when I overlay them, the bar chart gets scaled down to look incredibly useless... presumably because the scales of the two datasets are so different.

示例:

我真正想要的是拆分两个数据集的系列数据,并在左手Y轴上显示折线图的0-100范围,并使条形图显示为全尺寸,如下面的第一个示例所示,但比例尺0-5显示在图表的右侧Y轴上.

What I really want is to split the series data for the two datasets, and display the 0-100 range for the line chart on the left hand Y axis and to have the bar chart displayed full size as in my first example below, but have the scale 0-5 displayed on the right hand Y axis side of the graph.

要创建图形,我首先使用XYSeriesCollection创建条形图,添加数据并创建绘图...

To create the graph, I am first creating the bar chart using an XYSeriesCollection, adding the data and creating the plot...

XYSeriesCollection histogramDataset= new XYSeriesCollection();
XYSeries xy= new XYSeries("Temp");
xy.add(100,0.0);
xy.add(101,0.3769791404875597);
histogramDataset.addSeries(xy);
...
final NumberAxis xAxis = new NumberAxis("Temperature C");
xAxis.setAutoRangeIncludesZero(false);
final ValueAxis yAxis = new NumberAxis("Percent Time above Temperature");
final XYItemRenderer renderer = new XYBarRenderer();

final XYPlot plot = new XYPlot((XYDataset) histogramDataset, xAxis, yAxis, renderer);

然后我以类似的方式创建折线图,并将第二个系列添加到绘图中...

Then I create the line chart in a similar way and add the second series to the plot...

final XYSeries xy = new XYSeries("First");
final XYDataset xySeriesData = new XYSeriesCollection();
final XYItemRenderer xyLineRenderer = new XYLineAndShapeRenderer();
xyLineRenderer.setSeriesShape(0, new Line2D.Double(0.0, 0.0, 0.0, 0.0));
xyLineRenderer.setSeriesStroke(0, new BasicStroke(4.5f));
xy.add(100,100.0);
xy.add(101,100.0);
xyseriesData.add(xy);
plot.setDataset(1, xySeriesData);
plot.setRenderer(1, xyLineRenderer);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

我的怀疑是,每张图都需要以某种方式成为自己的图并组合在一起.有人可以帮忙吗?我要去的地方是这样的:

My suspicion is that somehow each graph needs to be it's own plot and combined together. Can anyone help? What I am going for here is something like this:

除了我不希望条形图成为背景图像. X轴应相同,Y轴应在右侧,并具有适当的比例,以使图形显示为完整尺寸.

Except I don't want the bar chart to be a background image. The X axis should be the same, and the Y axis should be on the right hand side with the proper scale that allows the graph to be shown full size.

任何/所有答复都受到赞赏...

Any/all replies are appreciated...

推荐答案

我看到您正在向绘图中添加第二个数据集和渲染器,但是您正在强迫它们使用相同的范围轴.取而代之的是,为该范围提供一个新的 NumberAxis 第二个数据集.

I see you're adding a second data set and renderer to your plot, but you're forcing them to use the same range axis. Instead, give the plot a new NumberAxis for the range of the second data set.

顺便说一句,请不要忽略 JFreeChart演示 ,请不要小看 JFreeChart开发人员指南 .

As an aside, don't overlook the axis related example in the JFreeChart Demo, and don't underestimate the value of the JFreeChart Developer Guide.

这篇关于帮助JFreeChart覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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