JFreeChart background color setting is not respected

不羁岁月 提交于 2019-12-11 11:33:27

问题


In JFreeChart I used to generate the chart with CategoryDataset and with createLineChart. This looked like this:

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);

But it does not work.

How can I change that background to white, and change the plot's background to gray (just like it was on the old one?)

Thanks!

UPDATE

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);

Here I would like to have the yellow as the background of the chartPanel.


回答1:


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.



来源:https://stackoverflow.com/questions/57604365/jfreechart-background-color-setting-is-not-respected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!