不遵守JFreeChart背景颜色设置 [英] JFreeChart background color setting is not respected
问题描述
在JFreeChart中,我曾经使用 CategoryDataset 和 createLineChart 生成图表.看起来像这样:
In JFreeChart I used to generate the chart with CategoryDataset and with createLineChart. This looked like this:
由于某些轴的更改,我不得不切换到 XYLineAndShapeRenderer ,现在的图表如下所示:
Due to some axis changes I had to switch to XYLineAndShapeRenderer, and now the chart looks like this:
请注意图表周围的灰色区域.我想将其更改为透明或至少白色,就像上面的旧字体一样.
Please notice the gray area around the chart. I want to change it to transparent or at least white just like it was on the old one above.
我尝试通过以下方式做到这一点:
I tried doing it by:
chart.getPlot().setBackgroundPaint(Color.WHITE);
但是它不起作用.
如何将背景更改为白色,并将情节的背景更改为灰色(就像旧背景一样?)
How can I change that background to white, and change the plot's background to gray (just like it was on the old one?)
谢谢!
我可以更新绘图的背景,但不能更新ChartPanel的背景.
I can update the plot's background, but not the ChartPanel's.
以下是具有以下选项的图:
Here is the diagram which has these options:
lineChart.getPlot().setBackgroundPaint(Color.red);
chartPanel.setBackground(Color.yellow);
在这里,我希望将黄色作为chartPanel的背景.
Here I would like to have the yellow as the background of the chartPanel.
推荐答案
这是用户错误.绘图周围的灰色区域不是ChartPanel
而是JFreeChart
本身.图表和绘图背景可以分别设置,例如:
It was a user error. The gray area around the plot was not the ChartPanel
but the JFreeChart
itself. The chart and plot backgrounds can be set separately, for example:
lineChart.setBackgroundPaint(Color.pink);
plot.setBackgroundPaint(Color.cyan.darker());
可以在此处看到完整的测试示例.
A complete example for testing is seen here.
这篇关于不遵守JFreeChart背景颜色设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!