使用 JFreeChart 从堆积条形图中删除网格线

Removing grid lines from stacked bar chart using JFreeChart

我使用 JasperStudio 创建了一个图表。我想删除图表中显示的网格线。我已尝试自定义图表,但自定义程序代码不起作用。这是我的代码:

    public void customize(JFreeChart chart, JRChart jrChart) {
    CategoryPlot cplot = (CategoryPlot) chart.getPlot();
    
    BarRenderer renderer = ((BarRenderer) cplot.getRenderer());
    renderer.setBarPainter(new StandardBarPainter());
    
    CategoryAxis xaxis = cplot.getDomainAxis();
    xaxis.setLabelLocation(AxisLabelLocation.MIDDLE);}

此代码无效。网格仍然显示。我应该怎么做才能删除它。谢谢

我自己想出来的。这可用于隐藏网格线:

    public void customize(JFreeChart chart, JRChart jrChart) {
    CategoryPlot cplot = (CategoryPlot) chart.getPlot();
//this will remove the horizontal grid lines    
    chart.getCategoryPlot().setRangeGridlinesVisible(false);
//if there are vertical grid lines, this line can be uncommented to hide those ones 
//  chart.getCategoryPlot().setDomainGridlinesVisible(false);}