    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2006, 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-2006, by Object Refinery Limited and Contributors.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   ;
    034     *
    035     * $Id: PieChartDemo1.java,v 1.2.2.4 2006/10/25 10:38:47 mungady Exp $
    036     *
    037     * Changes
    038     * -------
    039     * 09-Mar-2005 : Version 1, copied from the demo collection that ships with
    040     *               the JFreeChart Developer Guide (DG);
    041     *
    042     */
    043
    044    package org.jfree.chart.demo;
    045
    046    import java.awt.Font;
    047
    048    import javax.swing.JPanel;
    049
    050    import org.jfree.chart.ChartFactory;
    051    import org.jfree.chart.ChartPanel;
    052    import org.jfree.chart.JFreeChart;
    053    import org.jfree.chart.plot.PiePlot;
    054    import org.jfree.data.general.DefaultPieDataset;
    055    import org.jfree.data.general.PieDataset;
    056    import org.jfree.ui.ApplicationFrame;
    057    import org.jfree.ui.RefineryUtilities;
    058
    059    /**
    060     * A simple demonstration application showing how to create a pie chart using
    061     * data from a {@link DefaultPieDataset}.
    062     */
    063    public class PieChartDemo1 extends ApplicationFrame {
    064
    065        /**
    066         * Default constructor.
    067         *
    068         * @param title  the frame title.
    069         */
    070        public PieChartDemo1(String title) {
    071            super(title);
    072            setContentPane(createDemoPanel());
    073        }
    074
    075        /**
    076         * Creates a sample dataset.
    077         *
    078         * @return A sample dataset.
    079         */
    080        private static PieDataset createDataset() {
    081            DefaultPieDataset dataset = new DefaultPieDataset();
    082            dataset.setValue("One", new Double(43.2));
    083            dataset.setValue("Two", new Double(10.0));
    084            dataset.setValue("Three", new Double(27.5));
    085            dataset.setValue("Four", new Double(17.5));
    086            dataset.setValue("Five", new Double(11.0));
    087            dataset.setValue("Six", new Double(19.4));
    088            return dataset;
    089        }
    090
    091        /**
    092         * Creates a chart.
    093         *
    094         * @param dataset  the dataset.
    095         *
    096         * @return A chart.
    097         */
    098        private static JFreeChart createChart(PieDataset dataset) {
    099
    100            JFreeChart chart = ChartFactory.createPieChart(
    101                "Pie Chart Demo 1",  // chart title
    102                dataset,             // data
    103                true,               // include legend
    104                true,
    105                false
    106            );
    107
    108            PiePlot plot = (PiePlot) chart.getPlot();
    109            plot.setSectionOutlinesVisible(false);
    110            plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    111            plot.setNoDataMessage("No data available");
    112            plot.setCircular(false);
    113            plot.setLabelGap(0.02);
    114            return chart;
    115
    116        }
    117
    118        /**
    119         * Creates a panel for the demo (used by SuperDemo.java).
    120         *
    121         * @return A panel.
    122         */
    123        public static JPanel createDemoPanel() {
    124            JFreeChart chart = createChart(createDataset());
    125            return new ChartPanel(chart);
    126        }
    127
    128        /**
    129         * Starting point for the demonstration application.
    130         *
    131         * @param args  ignored.
    132         */
    133        public static void main(String[] args) {
    134
    135            // ******************************************************************
    136            //  More than 150 demo applications are included with the JFreeChart
    137            //  Developer Guide...for more information, see:
    138            //
    139            //  >   http://www.object-refinery.com/jfreechart/guide.html
    140            //
    141            // ******************************************************************
    142
    143            PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
    144            demo.pack();
    145            RefineryUtilities.centerFrameOnScreen(demo);
    146            demo.setVisible(true);
    147        }
    148
    149    }