Java/Chart/Pie Chart

Материал из Java эксперт
Перейти к: навигация, поиск

A pie chart comparing 2 Dataset (green increase, red decrease)

A pie chart showing one section exploded

A pie chart showing percentages on the category labels

Chart2D: Pie Chart

Chart: Simple Pie Chart

JCharts: Pie Chart

JFreeChart: Pie Chart Demo 1

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it 
* under the terms of the GNU Lesser General Public License as published by 
* the Free Software Foundation; either version 2.1 of the License, or 
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but 
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License 
* along with this library; if not, write to the Free Software Foundation, 
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo1.java
* ------------------
* (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   ;
*
* $Id: PieChartDemo1.java,v 1.2 2005/03/28 19:38:45 mungady Exp $
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
*               the JFreeChart Developer Guide (DG);
*
*/

package org.jfree.chart.demo; import java.awt.Font; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A simple demonstration application showing how to create a pie chart using 
* data from a {@link DefaultPieDataset}.
*/

public class PieChartDemo1 extends ApplicationFrame {

   /**
    * Default constructor.
    *
    * @param title  the frame title.
    */
   public PieChartDemo1(String title) {
       super(title);
       setContentPane(createDemoPanel());
   }
   /**
    * Creates a sample dataset.
    * 
    * @return A sample dataset.
    */
   private static PieDataset createDataset() {
       DefaultPieDataset dataset = new DefaultPieDataset();
       dataset.setValue("One", new Double(43.2));
       dataset.setValue("Two", new Double(10.0));
       dataset.setValue("Three", new Double(27.5));
       dataset.setValue("Four", new Double(17.5));
       dataset.setValue("Five", new Double(11.0));
       dataset.setValue("Six", new Double(19.4));
       return dataset;        
   }
   
   /**
    * Creates a chart.
    * 
    * @param dataset  the dataset.
    * 
    * @return A chart.
    */
   private static JFreeChart createChart(PieDataset dataset) {
       
       JFreeChart chart = ChartFactory.createPieChart(
           "Pie Chart Demo 1",  // chart title
           dataset,             // data
           true,               // include legend
           true,
           false
       );
       PiePlot plot = (PiePlot) chart.getPlot();
       plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
       plot.setNoDataMessage("No data available");
       plot.setCircular(false);
       plot.setLabelGap(0.02);
       return chart;
       
   }
   
   /**
    * Creates a panel for the demo (used by SuperDemo.java).
    * 
    * @return A panel.
    */
   public static JPanel createDemoPanel() {
       JFreeChart chart = createChart(createDataset());
       return new ChartPanel(chart);
   }
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(String[] args) {
       PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}


      </source>
   
  
 
  



JFreeChart: Pie Chart Demo 2

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo2.java
* ------------------
* (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: PieChartDemo2.java,v 1.13 2004/04/26 19:12:00 taqua Exp $
*
* Changes
* -------
* 05-Feb-2003 : Version 1 (DG);
* 10-Mar-2004 : Updated for rewritten pie chart classes (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A simple demonstration application showing how to create a pie chart using data from a
* {@link DefaultPieDataset}.  This demo also shows an "exploded" section in the chart.
*
*/

public class PieChartDemo2 extends ApplicationFrame {

   /**
    * Default constructor.
    *
    * @param title  the frame title.
    */
   public PieChartDemo2(final String title) {
       super(title);
       final PieDataset dataset = createDataset();
       final JFreeChart chart = createChart(dataset);
       // add the chart to a panel...
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Creates a sample dataset.
    * 
    * @return a sample dataset.
    */
   private PieDataset createDataset() {
       final DefaultPieDataset dataset = new DefaultPieDataset();
       dataset.setValue("One", new Double(43.2));
       dataset.setValue("Two", new Double(10.0));
       dataset.setValue("Three", new Double(27.5));
       dataset.setValue("Four", new Double(17.5));
       dataset.setValue("Five", new Double(11.0));
       dataset.setValue("Six", new Double(19.4));
       return dataset;
   }
   
   /**
    * Creates a sample chart.
    * 
    * @param dataset  the dataset.
    * 
    * @return a chart.
    */
   private JFreeChart createChart(final PieDataset dataset) {
       final JFreeChart chart = ChartFactory.createPieChart(
           "Pie Chart Demo 2",  // chart title
           dataset,             // dataset
           true,                // include legend
           true,
           false
       );
       final PiePlot plot = (PiePlot) chart.getPlot();
       plot.setNoDataMessage("No data available");
       plot.setExplodePercent(1, 0.30);
       return chart;
   }
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final PieChartDemo2 demo = new PieChartDemo2("Pie Chart Demo 2");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: Pie Chart Demo 4

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo4.java
* ------------------
* (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: PieChartDemo4.java,v 1.21 2004/06/03 15:05:10 mungady Exp $
*
* Changes
* -------
* 11-Feb-2003 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.NumberFormat; import javax.swing.Timer; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.labels.StandardPieItemLabelGenerator; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; import org.jfree.util.Log; import org.jfree.util.PrintStreamLogTarget; /**

* A simple demonstration application showing how to create a pie chart using data from a
* {@link DefaultPieDataset}.  This chart has a lot of labels and rotates, so it is useful for
* testing the label distribution algorithm.
*/

public class PieChartDemo4 extends ApplicationFrame {

   /**
    * Default constructor.
    *
    * @param title  the frame title.
    */
   public PieChartDemo4(final String title) {
       super(title);
       final PieDataset dataset = createDataset(14);
       // create the chart...
       final JFreeChart chart = ChartFactory.createPieChart(
           "Pie Chart Demo 4",  // chart title
           dataset,             // dataset
           false,               // include legend
           true,
           false
       );
       // set the background color for the chart...
       chart.setBackgroundPaint(new Color(222, 222, 255));
       final PiePlot plot = (PiePlot) chart.getPlot();
       plot.setBackgroundPaint(Color.white);
       plot.setCircular(true);
       plot.setLabelGenerator(new StandardPieItemLabelGenerator(
           "{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()
       ));
       plot.setNoDataMessage("No data available");
       // add the chart to a panel...
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
       
       final Rotator rotator = new Rotator(plot);
       rotator.start();
   }
   /**
    * Creates a sample dataset.
    * 
    * @param sections  the number of sections.
    * 
    * @return A sample dataset.
    */
   private PieDataset createDataset(final int sections) {
       final DefaultPieDataset result = new DefaultPieDataset();
       for (int i = 0; i < sections; i++) {
           final double value = 100.0 * Math.random();
           result.setValue("Section " + i, value);
       }
       return result;
   }
   
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       Log.getInstance().addTarget(new PrintStreamLogTarget());
       final PieChartDemo4 demo = new PieChartDemo4("Pie Chart Demo 4");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }
   /**
    * The rotator.
    *
    */
   static class Rotator extends Timer implements ActionListener {
       /** The plot. */
       private PiePlot plot;
       /** The angle. */
       private int angle = 270;
       /**
        * Constructor.
        *
        * @param plot  the plot.
        */
       Rotator(final PiePlot plot) {
           super(100, null);
           this.plot = plot;
           addActionListener(this);
       }
       /**
        * Modifies the starting angle.
        *
        * @param event  the action event.
        */
       public void actionPerformed(final ActionEvent event) {
           this.plot.setStartAngle(angle);
           this.angle = this.angle + 1;
           if (this.angle == 360) {
               this.angle = 0;
           }
       }
   }

}

      </source>
   
  
 
  



JFreeChart: Pie Chart Demo 5

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo5.java
* ------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: PieChartDemo5.java,v 1.2 2004/04/26 19:12:00 taqua Exp $
*
* Changes
* -------
* 31-Mar-2004 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A pie chart with no section labels.
*/

public class PieChartDemo5 extends ApplicationFrame {

   /**
    * Creates a new demo instance.
    *
    * @param title  the frame title.
    */
   public PieChartDemo5(final String title) {
       super(title);
       final PieDataset dataset = createDataset();
       final JFreeChart chart = createChart(dataset);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   /**
    * Creates a sample dataset.
    * 
    * @return a sample dataset.
    */
   private PieDataset createDataset() {
       final DefaultPieDataset dataset = new DefaultPieDataset();
       dataset.setValue("One", new Double(43.2));
       dataset.setValue("Two", new Double(10.0));
       dataset.setValue("Three", new Double(27.5));
       dataset.setValue("Four", new Double(17.5));
       dataset.setValue("Five", new Double(11.0));
       dataset.setValue("Six", new Double(19.4));
       return dataset;        
   }
   
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Creates a chart.
    * 
    * @param dataset  the dataset.
    * 
    * @return a chart.
    */
   private JFreeChart createChart(final PieDataset dataset) {
       
       final JFreeChart chart = ChartFactory.createPieChart(
           "Pie Chart Demo 5",  // chart title
           dataset,             // data
           false,               // include legend
           true,
           false
       );
       final PiePlot plot = (PiePlot) chart.getPlot();
       plot.setInteriorGap(0.0);
       plot.setLabelGenerator(null);
       return chart;
       
   }
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final PieChartDemo5 demo = new PieChartDemo5("Pie Chart Demo 5");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}


      </source>
   
  
 
  



JFreeChart: Pie Chart Demo 6

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo6.java
* ------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: PieChartDemo6.java,v 1.3 2004/04/26 19:12:00 taqua Exp $
*
* Changes
* -------
* 31-Mar-2004 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.labels.PieSectionLabelGenerator; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A pie chart with a custom label generator.
*/

public class PieChartDemo6 extends ApplicationFrame {

   /**
    * Creates a new demo instance.
    *
    * @param title  the frame title.
    */
   public PieChartDemo6(final String title) {
       super(title);
       final PieDataset dataset = createDataset();
       final JFreeChart chart = createChart(dataset);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   /**
    * Creates a sample dataset.
    * 
    * @return a sample dataset.
    */
   private PieDataset createDataset() {
       final DefaultPieDataset dataset = new DefaultPieDataset();
       dataset.setValue("One", new Double(43.2));
       dataset.setValue("Two", new Double(10.0));
       dataset.setValue("Three", new Double(27.5));
       dataset.setValue("Four", new Double(17.5));
       dataset.setValue("Five", new Double(11.0));
       dataset.setValue("Six", new Double(19.4));
       return dataset;        
   }
   
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Creates a chart.
    * 
    * @param dataset  the dataset.
    * 
    * @return a chart.
    */
   private JFreeChart createChart(final PieDataset dataset) {
       
       final JFreeChart chart = ChartFactory.createPieChart(
           "Pie Chart Demo 6",  // chart title
           dataset,             // data
           false,               // include legend
           true,
           false
       );
       final PiePlot plot = (PiePlot) chart.getPlot();
       plot.setLabelGenerator(new CustomLabelGenerator());
       return chart;
       
   }
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final PieChartDemo6 demo = new PieChartDemo6("Pie Chart Demo 6");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }
   
   /**
    * A custom label generator (returns null for one item as a test).
    */
   static class CustomLabelGenerator implements PieSectionLabelGenerator {
       
       /**
        * Generates a label for a pie section.
        * 
        * @param dataset  the dataset (null not permitted).
        * @param key  the section key (null not permitted).
        * 
        * @return the label (possibly null).
        */
       public String generateSectionLabel(final PieDataset dataset, final Comparable key) {
           String result = null;    
           if (dataset != null) {
               if (!key.equals("Two")) {
                   result = key.toString();   
               }
           }
           return result;
       }
  
   }

}


      </source>
   
  
 
  



JFreeChart: Pie Chart Demo 7

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* PieChartDemo7.java
* ------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: PieChartDemo7.java,v 1.1 2004/05/26 13:02:03 mungady Exp $
*
* Changes
* -------
* 25-May-2004 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.PiePlot3D; import org.jfree.data.general.DefaultPieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A demo showing four pie charts.
*/

public class PieChartDemo7 extends ApplicationFrame {

   /**
    * Creates a new demo instance.
    * 
    * @param title  the frame title.
    */
   public PieChartDemo7(String title) {
       super(title);
       JPanel panel = new JPanel(new GridLayout(2, 2));
       DefaultPieDataset dataset = new DefaultPieDataset();
       dataset.setValue("Section 1", 23.3);
       dataset.setValue("Section 2", 56.5);
       dataset.setValue("Section 3", 43.3);
       dataset.setValue("Section 4", 11.1);
       
       JFreeChart chart1 = ChartFactory.createPieChart("Chart 1", dataset, false, false, false);
       JFreeChart chart2 = ChartFactory.createPieChart("Chart 2", dataset, false, false, false);
       PiePlot plot2 = (PiePlot) chart2.getPlot();
       plot2.setCircular(false);
       JFreeChart chart3 = ChartFactory.createPieChart3D("Chart 3", dataset, false, false, false);
       PiePlot3D plot3 = (PiePlot3D) chart3.getPlot();
       plot3.setForegroundAlpha(0.6f);
       plot3.setCircular(true);
       JFreeChart chart4 = ChartFactory.createPieChart3D("Chart 4", dataset, false, false, false);
       PiePlot3D plot4 = (PiePlot3D) chart4.getPlot();
       plot4.setForegroundAlpha(0.6f);
       panel.add(new ChartPanel(chart1));
       panel.add(new ChartPanel(chart2));
       panel.add(new ChartPanel(chart3));
       panel.add(new ChartPanel(chart4));
       panel.setPreferredSize(new Dimension(800, 600));
       setContentPane(panel);
   }
   /**
    * The starting point for the demo.
    * 
    * @param args  ignored.
    */
   public static void main(String[] args) {
       PieChartDemo7 demo = new PieChartDemo7("Pie Chart Demo 7");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>