augarte Posted November 12, 2012 Share Posted November 12, 2012 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 Link to comment Share on other sites More sharing options...
augarte Posted November 12, 2012 Author Share Posted November 12, 2012 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 More sharing options...
lucianc Posted November 12, 2012 Share Posted November 12, 2012 Looking at the JFreeChart sources, it doesn't seem possible to use the section color as label background. You can ask on the JFreeChart forum though, maybe I'm missing something. Regards, Lucian Link to comment Share on other sites More sharing options...
sanbez Posted November 14, 2012 Share Posted November 14, 2012 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 More sharing options...
sanbez Posted November 15, 2012 Share Posted November 15, 2012 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 More sharing options...
augarte Posted November 15, 2012 Author Share Posted November 15, 2012 Thanks so much sanbez! Now I'm really busy but I'll try to change jfreechart code and I'll let you know. Best regards, Aitor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now