I have a data source in which there are three departments and each department has equal employees that are 8. I want to make a pie chart using jFreeChart such that first we partition the pie into 3 equal parts for departments that is 120' for each department. Then in these partitions I want to show the sales of each employee. How can I do this in jFreeChart.
Asked
Active
Viewed 470 times
2 Answers
2
PieChartDemo1
is a good starting point; focus on createDataset()
; the full source is included in the distribution.
Addendum: How to further create partitions?
Ah, you want to sub-divide each 120° partition. DefaultPieDataset
doesn't support a hierarchical structure directly, but you can use color in the PiePlot
to highlight the grouping. Create related colors using Color.getHSBColor()
, as shown here, and use setSectionPaint()
to apply the colors accordingly.
-
Its simple to create partitions but how to further create partitions in that? Thanks. – wali Jun 27 '13 at 09:58
-
I've suggested one approach above. – trashgod Jun 27 '13 at 11:26
2
public class PieChart extends JFrame {
private PieDataset createDataset() {
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("department1", 33.33);
result.setValue("department2", 33.33);
result.setValue("department3", 33.33);
return result;
}
private JFreeChart createChart(PieDataset dataset, String title) {
JFreeChart chart = ChartFactory.createPieChart3D(title, // chart title
dataset, // data
true, // include legend
true,
false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);
return chart;
}
}
public static void main(String[] args) {
PieChart demo = new PieChart("Comparison", "Which operating system are you using?");
demo.pack();
demo.setVisible(true);
}

shreyansh jogi
- 2,082
- 12
- 20
-
Its simple to create partitions but how to further create partitions in that? Thanks. – wali Jun 27 '13 at 10:09
-
make paratition accordingly means pie chart usefull to partition so when you assigning any student then your 100% will be 33.33 as per department partition assign value below 33.33 and if you want to assign each 8 student equal then 33.33/8 – shreyansh jogi Jun 27 '13 at 10:09