wali
wali

Reputation: 239

Partition pie chart into equal parts jfreechart

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.

Upvotes: 0

Views: 508

Answers (2)

trashgod
trashgod

Reputation: 205875

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.

Upvotes: 2

shreyansh jogi
shreyansh jogi

Reputation: 2102

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);
      }

Upvotes: 2

Related Questions