Jump to content
We've recently updated our Privacy Statement, available here ×

Pie Chart customization


augarte

Recommended Posts

Hi, 

I've managed to create a Pie Chart using my datasource. Now, I would like to do couple of modifications but don't know if this is possible. This is what I want to do: 

- Show the percentages with two decimals.

- Paint the background of the rectangle where the percentages are shown with the colour that corresponds to each key ("Movimiento", "Ralenti" and "Toma de fuerza")

Is this possible? Do I have to use JRAbstractChartCustomizer or any other chart customizer?

I add an image to see how my pie chart looks.

Thanks in advance. 

Kind regards

PieChart.png.c8eef9e76ee8294dbaf1eb5a0b28a432.png

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

I could solve the first question using JFreeChart customizer:

 

public void customize(JFreeChart chart, JRChart jasperChart) {

 

PiePlot3D piePlot3D = (PiePlot3D) chart.getPlot();

((StandardPieSectionLabelGenerator) piePlot3D.getLabelGenerator()).getPercentFormat().setMaximumFractionDigits(2);

}

 

Does anybody know if it is possible doing the second thing? I have chekced setLabelBackgroundPaint function and it is possible to paint the label background with a diffrente colour, but it paints all the labels with the same colour.

Link to comment
Share on other sites

Interesting questions! Only one private field present in org.jfree.chart.plot.PiePlot

/** The color used to draw the background of the section labels. */

private transient Paint labelBackgroundPaint;

 

source for draw labels:

for (...) {

TextBox labelBox = new TextBox(block);

labelBox.setBackgroundPaint(this.labelBackgroundPaint);

}

 

Probably, it is possible write own class extends org.jfree.chart.plot.PiePlot and override 2-3 methods of this class. But is it possible "deceive" jasper and use my own class instead org.jfree.chart.plot.PiePlot ?

Link to comment
Share on other sites

Make change in org.jfree.chart.plot.PiePlot.java in methods "drawLeftLabels" and "drawRightLabels":
drawLeftLabels

                // was:
                // labelBox.setBackgroundPaint(this.labelBackgroundPaint);
                // now:
                labelBox.setBackgroundPaint(lookupSectionPaint(leftKeys.getKey(i)));
drawRightLabels

                // was
                // labelBox.setBackgroundPaint(this.labelBackgroundPaint);
                // now
                labelBox.setBackgroundPaint(lookupSectionPaint(keys.getKey(i)));

and rebuild jfreechart-1.0.12.jar you get:


But it will act on all reports PieChart (and PieChart3D)
 






 

 

 

Link to comment
Share on other sites

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...