Hi,
I would like to set the color of each section of a pie chart and not use the default as provided by the program. Can you please advise the code required to achieve this?
Many Thanks
Hi,
I would like to set the color of each section of a pie chart and not use the default as provided by the program. Can you please advise the code required to achieve this?
Many Thanks
Tom,
Here is the code. You can change the colors in the plot.setSectionPaint(1, new Color(0,102,102)) ... Each Pie section is identified by the number 1, 2, 3.. and Color(R,G,B) defines the color associated with that section
//-------------
//import the necessary classes
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
plot =((PiePlot3D) chart.getPlot());
plot.setForegroundAlpha(0.5f);
//chart.setBackgroundPaint(new GradientPaint(0,0,Color.gray.brighter().brighter(),0,displayFrame.getHeight(), Color.LIGHT_GRAY));
float h = displayFrame.getHeight();
float w = displayFrame.getWidth();
GradientPaint gradientPaint = new GradientPaint(0.0F, 10.0F, Color.white, 0, h, Color.orange);
// plot.setBackgroundPaint(gradientPaint);
chart.getTitle().setPaint(Color.blue);
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2} {0}={1}"));
plot.setSectionPaint(1, new Color(0,102,102));
plot.setSectionPaint(2, new Color(51,0,102));
plot.setSectionPaint(3, new Color(102,0,102));
plot.setSectionPaint(4, new Color(102,0,0));
plot.setSectionPaint(5, new Color(51,51,0));
plot.setSectionPaint(6, new Color(0,51,0));
plot.setSectionPaint(7, new Color(0,102,51));
You must log in to post.