Jamshaid
Jamshaid

Reputation: 410

Removing grid lines from stacked bar chart using JFreeChart

I have created a chart using JasperStudio. I want to remove the gridlines being displayed in chart. I have tried customizing the Chart but the customizer code is not working. Here is my code:

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

this code is not working. The grid still keeps displaying. What should I do to remove it. Thanks

Upvotes: 1

Views: 481

Answers (1)

Jamshaid
Jamshaid

Reputation: 410

I figured it out by myself. This can be used to hide grid lines:

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

Upvotes: 1

Related Questions