    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
    006     *
    007     * Project Info:  http://www.jfree.org/jfreechart/index.html
    008     *
    009     * This library is free software; you can redistribute it and/or modify it
    010     * under the terms of the GNU Lesser General Public License as published by
    011     * the Free Software Foundation; either version 2.1 of the License, or
    012     * (at your option) any later version.
    013     *
    014     * This library is distributed in the hope that it will be useful, but
    015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    017     * License for more details.
    018     *
    019     * You should have received a copy of the GNU Lesser General Public
    020     * License along with this library; if not, write to the Free Software
    021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    022     * USA.
    023     *
    024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
    025     * in the United States and other countries.]
    026     *
    027     * ------------------
    028     * PieChartDemo1.java
    029     * ------------------
    030     * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   ;
    034     *
    035     * Changes
    036     * -------
    037     * 09-Mar-2005 : Version 1, copied from the demo collection that ships with
    038     *               the JFreeChart Developer Guide (DG);
    039     *
    040     */
    041
    042    package org.jfree.chart.demo;
    043
    044    import java.awt.Font;
    045
    046    import javax.swing.JPanel;
    047
    048    import org.jfree.chart.ChartFactory;
    049    import org.jfree.chart.ChartPanel;
    050    import org.jfree.chart.JFreeChart;
    051    import org.jfree.chart.plot.PiePlot;
    052    import org.jfree.data.general.DefaultPieDataset;
    053    import org.jfree.data.general.PieDataset;
    054    import org.jfree.ui.ApplicationFrame;
    055    import org.jfree.ui.RefineryUtilities;
    056
    057    /**
    058     * A simple demonstration application showing how to create a pie chart using
    059     * data from a {@link DefaultPieDataset}.
    060     */
    061    public class PieChartDemo1 extends ApplicationFrame {
    062
    063        /**
    064         * Default constructor.
    065         *
    066         * @param title  the frame title.
    067         */
    068        public PieChartDemo1(String title) {
    069            super(title);
    070            setContentPane(createDemoPanel());
    071        }
    072
    073        /**
    074         * Creates a sample dataset.
    075         *
    076         * @return A sample dataset.
    077         */
    078        private static PieDataset createDataset() {
    079            DefaultPieDataset dataset = new DefaultPieDataset();
    080            dataset.setValue("One", new Double(43.2));
    081            dataset.setValue("Two", new Double(10.0));
    082            dataset.setValue("Three", new Double(27.5));
    083            dataset.setValue("Four", new Double(17.5));
    084            dataset.setValue("Five", new Double(11.0));
    085            dataset.setValue("Six", new Double(19.4));
    086            return dataset;
    087        }
    088
    089        /**
    090         * Creates a chart.
    091         *
    092         * @param dataset  the dataset.
    093         *
    094         * @return A chart.
    095         */
    096        private static JFreeChart createChart(PieDataset dataset) {
    097
    098            JFreeChart chart = ChartFactory.createPieChart(
    099                "Pie Chart Demo 1",  // chart title
    100                dataset,             // data
    101                true,               // include legend
    102                true,
    103                false
    104            );
    105
    106            PiePlot plot = (PiePlot) chart.getPlot();
    107            plot.setSectionOutlinesVisible(false);
    108            plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    109            plot.setNoDataMessage("No data available");
    110            plot.setSimpleLabels(true);
    111            return chart;
    112
    113        }
    114
    115        /**
    116         * Creates a panel for the demo (used by SuperDemo.java).
    117         *
    118         * @return A panel.
    119         */
    120        public static JPanel createDemoPanel() {
    121            JFreeChart chart = createChart(createDataset());
    122            return new ChartPanel(chart);
    123        }
    124
    125        /**
    126         * Starting point for the demonstration application.
    127         *
    128         * @param args  ignored.
    129         */
    130        public static void main(String[] args) {
    131
    132            // ******************************************************************
    133            //  More than 150 demo applications are included with the JFreeChart
    134            //  Developer Guide...for more information, see:
    135            //
    136            //  >   http://www.object-refinery.com/jfreechart/guide.html
    137            //
    138            // ******************************************************************
    139
    140            PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
    141            demo.pack();
    142            RefineryUtilities.centerFrameOnScreen(demo);
    143            demo.setVisible(true);
    144        }
    145
    146    }