JFreeChart 背景颜色设置不受尊重
JFreeChart background color setting is not respected
在 JFreeChart 中,我曾经使用 CategoryDataset 和 createLineChart 生成图表。这看起来像这样:
由于某些轴的变化,我不得不切换到 XYLineAndShapeRenderer,现在图表如下所示:
请注意图表周围的灰色区域。我想将其更改为透明或至少是白色,就像上面的旧版本一样。
我试过这样做:
chart.getPlot().setBackgroundPaint(Color.WHITE);
但是不行。
如何将该背景更改为白色,并将绘图的背景更改为灰色(就像在旧背景上一样?)
谢谢!
更新
我可以更新图表的背景,但不能更新图表面板的背景。
这是包含这些选项的图表:
lineChart.getPlot().setBackgroundPaint(Color.red);
chartPanel.setBackground(Color.yellow);
这里我想把黄色作为chartPanel的背景。
这是用户错误。图周围的灰色区域不是 ChartPanel
,而是 JFreeChart
本身。图表和绘图背景可以单独设置,例如:
lineChart.setBackgroundPaint(Color.pink);
plot.setBackgroundPaint(Color.cyan.darker());
已查看完整的测试示例。
在 JFreeChart 中,我曾经使用 CategoryDataset 和 createLineChart 生成图表。这看起来像这样:
由于某些轴的变化,我不得不切换到 XYLineAndShapeRenderer,现在图表如下所示:
请注意图表周围的灰色区域。我想将其更改为透明或至少是白色,就像上面的旧版本一样。
我试过这样做:
chart.getPlot().setBackgroundPaint(Color.WHITE);
但是不行。
如何将该背景更改为白色,并将绘图的背景更改为灰色(就像在旧背景上一样?)
谢谢!
更新
我可以更新图表的背景,但不能更新图表面板的背景。
这是包含这些选项的图表:
lineChart.getPlot().setBackgroundPaint(Color.red);
chartPanel.setBackground(Color.yellow);
这里我想把黄色作为chartPanel的背景。
这是用户错误。图周围的灰色区域不是 ChartPanel
,而是 JFreeChart
本身。图表和绘图背景可以单独设置,例如:
lineChart.setBackgroundPaint(Color.pink);
plot.setBackgroundPaint(Color.cyan.darker());
已查看完整的测试示例