    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 javax.swing.JPanel;
    045
    046    import org.jfree.chart.ChartFactory;
    047    import org.jfree.chart.ChartPanel;
    048    import org.jfree.chart.JFreeChart;
    049    import org.jfree.chart.plot.PiePlot;
    050    import org.jfree.data.general.DefaultPieDataset;
    051    import org.jfree.data.general.PieDataset;
    052    import org.jfree.ui.ApplicationFrame;
    053    import org.jfree.ui.RefineryUtilities;
    054
    055    /**
    056     * A simple demonstration application showing how to create a pie chart using
    057     * data from a {@link DefaultPieDataset}.
    058     */
    059    public class PieChartDemo1 extends ApplicationFrame {
    060
    061        /**
    062         * Default constructor.
    063         *
    064         * @param title  the frame title.
    065         */
    066        public PieChartDemo1(String title) {
    067            super(title);
    068            setContentPane(createDemoPanel());
    069        }
    070
    071        /**
    072         * Creates a sample dataset.
    073         *
    074         * @return A sample dataset.
    075         */
    076        private static PieDataset createDataset() {
    077            DefaultPieDataset dataset = new DefaultPieDataset();
    078            dataset.setValue("One", new Double(43.2));
    079            dataset.setValue("Two", new Double(10.0));
    080            dataset.setValue("Three", new Double(27.5));
    081            dataset.setValue("Four", new Double(17.5));
    082            dataset.setValue("Five", new Double(11.0));
    083            dataset.setValue("Six", new Double(19.4));
    084            return dataset;
    085        }
    086
    087        /**
    088         * Creates a chart.
    089         *
    090         * @param dataset  the dataset.
    091         *
    092         * @return A chart.
    093         */
    094        private static JFreeChart createChart(PieDataset dataset) {
    095
    096            JFreeChart chart = ChartFactory.createPieChart(
    097                "Pie Chart Demo 1",  // chart title
    098                dataset,             // data
    099                true,               // include legend
    100                true,
    101                false
    102            );
    103
    104            PiePlot plot = (PiePlot) chart.getPlot();
    105            plot.setSectionOutlinesVisible(false);
    106            plot.setNoDataMessage("No data available");
    107
    108            return chart;
    109
    110        }
    111
    112        /**
    113         * Creates a panel for the demo (used by SuperDemo.java).
    114         *
    115         * @return A panel.
    116         */
    117        public static JPanel createDemoPanel() {
    118            JFreeChart chart = createChart(createDataset());
    119            return new ChartPanel(chart);
    120        }
    121
    122        /**
    123         * Starting point for the demonstration application.
    124         *
    125         * @param args  ignored.
    126         */
    127        public static void main(String[] args) {
    128
    129            // ******************************************************************
    130            //  More than 150 demo applications are included with the JFreeChart
    131            //  Developer Guide...for more information, see:
    132            //
    133            //  >   http://www.object-refinery.com/jfreechart/guide.html
    134            //
    135            // ******************************************************************
    136
    137            PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
    138            demo.pack();
    139            RefineryUtilities.centerFrameOnScreen(demo);
    140            demo.setVisible(true);
    141        }
    142
    143    }