001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2011, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ------------------
028 * PieChartDemo1.java
029 * ------------------
030 * (C) Copyright 2003-2011, 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
042package org.jfree.chart.demo;
043
044import javax.swing.JPanel;
045
046import org.jfree.chart.ChartFactory;
047import org.jfree.chart.ChartPanel;
048import org.jfree.chart.JFreeChart;
049import org.jfree.chart.StandardChartTheme;
050import org.jfree.chart.plot.PiePlot;
051import org.jfree.data.general.DefaultPieDataset;
052import org.jfree.data.general.PieDataset;
053import org.jfree.ui.ApplicationFrame;
054import org.jfree.ui.RefineryUtilities;
055
056/**
057 * A simple demonstration application showing how to create a pie chart using
058 * data from a {@link DefaultPieDataset}.
059 */
060public class PieChartDemo1 extends ApplicationFrame {
061
062    private static final long serialVersionUID = 1L;
063
064    {
065        // set a theme using the new shadow generator feature available in
066        // 1.0.14 - for backwards compatibility it is not enabled by default
067        ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow",
068                true));
069    }
070
071    /**
072     * Default constructor.
073     *
074     * @param title  the frame title.
075     */
076    public PieChartDemo1(String title) {
077        super(title);
078        setContentPane(createDemoPanel());
079    }
080
081    /**
082     * Creates a sample dataset.
083     *
084     * @return A sample dataset.
085     */
086    private static PieDataset createDataset() {
087        DefaultPieDataset dataset = new DefaultPieDataset();
088        dataset.setValue("One", new Double(43.2));
089        dataset.setValue("Two", new Double(10.0));
090        dataset.setValue("Three", new Double(27.5));
091        dataset.setValue("Four", new Double(17.5));
092        dataset.setValue("Five", new Double(11.0));
093        dataset.setValue("Six", new Double(19.4));
094        return dataset;
095    }
096
097    /**
098     * Creates a chart.
099     *
100     * @param dataset  the dataset.
101     *
102     * @return A chart.
103     */
104    private static JFreeChart createChart(PieDataset dataset) {
105
106        JFreeChart chart = ChartFactory.createPieChart(
107            "Pie Chart Demo 1",  // chart title
108            dataset,             // data
109            true,                // include legend
110            true,
111            false
112        );
113
114        PiePlot plot = (PiePlot) chart.getPlot();
115        plot.setSectionOutlinesVisible(false);
116        plot.setNoDataMessage("No data available");
117        return chart;
118
119    }
120
121    /**
122     * Creates a panel for the demo (used by SuperDemo.java).
123     *
124     * @return A panel.
125     */
126    public static JPanel createDemoPanel() {
127        JFreeChart chart = createChart(createDataset());
128        ChartPanel panel = new ChartPanel(chart);
129        panel.setMouseWheelEnabled(true);
130        return panel;
131    }
132
133    /**
134     * Starting point for the demonstration application.
135     *
136     * @param args  ignored.
137     */
138    public static void main(String[] args) {
139
140        // ******************************************************************
141        //  More than 150 demo applications are included with the JFreeChart
142        //  Developer Guide...for more information, see:
143        //
144        //  >   http://www.object-refinery.com/jfreechart/guide.html
145        //
146        // ******************************************************************
147
148        PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
149        demo.pack();
150        RefineryUtilities.centerFrameOnScreen(demo);
151        demo.setVisible(true);
152    }
153
154}