Jump to content
Changes to the Jaspersoft community edition download ×

How to Change Legend Label Text (PieChart)


casi91

Recommended Posts

Hi,

In my PieChart i only want to show the biggest 5 values and "others". But i want to change the Labeltext "others" to "andere". I've tried to write a ChartCustomizer, but i didn't found de right place, where I can replace the Labeltext.

Hier my Code so far:

    @Override
    public void customize(JFreeChart jFreeChart, JRChart jrChart) {
        if (jFreeChart.getPlot().getClass().equals(PiePlot3D.class)) {
            formatPiePlot3D((PiePlot3D) jFreeChart.getPlot());            
        } else if (jFreeChart.getPlot().getClass().equals(PiePlot.class)) {
            formatPiePlot((PiePlot) jFreeChart.getPlot());
        }
    }

    private void formatPiePlot3D(PiePlot3D plot) {
        LegendItemCollection lic  = plot.getLegendItems();
        changeLegendItemCollection(lic);
    }
    
    private void formatPiePlot(PiePlot plot) {
        LegendItemCollection lic     = plot.getLegendItems();
        changeLegendItemCollection(lic);
    }   

private void changeLegendItemCollection(LegendItemCollection lic) {
        for (int i=0; i < lic.getItemCount(); i++) {
            LegendItem li             = lic.get(i);
            System.out.println(li.getLabel());
            if (li.getLabel().toUpperCase().substring(0, 5).trim().equals("OTHER")) {
                System.out.println("foundit");
                li.setLabelFont(new Font("TimesRoman", Font.ITALIC, 20));
            }
        }            
    }

 

I hope somebody can help me.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...