You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JFreeChart堆叠面积图移除网格线问题求助

解决JFreeChart堆叠面积图移除网格线的问题

嘿,别发愁啦!看了你的代码,其实你已经找对方向了,只是有个小细节可以调整得更彻底~

你已经尝试用setDomainGridlinesVisible(false)和setRangeGridlinesVisible(false)来关闭网格线,这本身是正确的做法。不过你额外设置了setDomainGridlinePaint(Color.white)和setRangeGridlinePaint(Color.white),这步其实没必要(毕竟网格线已经设为不可见了),而且有时候可能会因为渲染顺序的问题出现意外。

直接修改这部分代码,只保留关闭网格线的核心逻辑,就能彻底移除网格线了:

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
// 移除网格线的核心代码
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
// 其他你的设置保持不变
plot.getRenderer().setSeriesPaint(0, new java.awt.Color(0, 0, 128));
plot.getRenderer().setSeriesPaint(1, new java.awt.Color(192, 80, 77));
plot.getRenderer().setSeriesPaint(2, new java.awt.Color(155, 187, 83));
plot.getRenderer().setSeriesPaint(3, new java.awt.Color(79, 129, 189));
plot.getRenderer().setSeriesPaint(4, new java.awt.Color(75, 0, 130));
plot.getRenderer().setSeriesPaint(5, new java.awt.Color(233, 125, 35));
plot.setBackgroundPaint(Color.WHITE);
plot.setNoDataMessage("No data found");

另外给你个小提示:之后遇到类似的图表元素调整问题,可以直接查看CategoryPlot的API文档,里面关于网格线、背景、坐标轴的设置都写得很清晰,比盲目搜索效率高很多哦~

内容的提问来源于stack exchange,提问作者Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:38:23