001/* ======================================================
002 * Orson : a free chart beans library based on JFreeChart
003 * ======================================================
004 *
005 * (C) Copyright 2007, by Object Refinery Limited.
006 *
007 * Project Info:  http://www.jfree.org/orson/
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
029package org.jfree.beans;
030
031import java.awt.Color;
032import java.beans.PropertyChangeEvent;
033
034import org.jfree.chart.ChartFactory;
035import org.jfree.chart.JFreeChart;
036import org.jfree.chart.plot.PlotOrientation;
037import org.jfree.chart.plot.XYPlot;
038import org.jfree.data.xy.XYDataset;
039import org.jfree.data.xy.XYSeries;
040import org.jfree.data.xy.XYSeriesCollection;
041import org.jfree.ui.RectangleInsets;
042
043/**
044 * A JavaBean that displays an area chart.
045 */
046public class JAreaChart extends NumericalXYChart {
047    
048    /**
049     * Creates a new pie chart bean.
050     */
051    public JAreaChart() {
052        super();
053    }
054    
055    /**
056     * Creates a default chart.
057     * 
058     * @return The default chart.
059     */
060    protected JFreeChart createDefaultChart() {
061        XYSeriesCollection dataset = new XYSeriesCollection();
062        XYSeries s1 = new XYSeries("Series 1");
063        s1.add(1.0, 5.0);
064        s1.add(2.0, 7.0);
065        s1.add(3.0, 3.0);
066        s1.add(4.0, 6.0);
067        dataset.addSeries(s1);
068        JFreeChart chart = ChartFactory.createXYAreaChart("JAreaChart - Title", 
069                "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
070        XYPlot plot = (XYPlot) chart.getPlot();
071        plot.setBackgroundPaint(Color.lightGray);
072        plot.setDomainGridlinePaint(Color.white);
073        plot.setRangeGridlinePaint(Color.white);
074        plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
075
076        return chart;
077    }
078    
079    /**
080     * Returns the dataset used by the chart.
081     * 
082     * @return The dataset (possibly <code>null</code>).
083     * 
084     * @see #setDataset(XYDataset)
085     */
086    public XYDataset getDataset() {
087        XYDataset result = null;
088        XYPlot plot = (XYPlot) this.chart.getPlot();
089        if (plot != null) {
090            result = plot.getDataset();
091        }
092        return result;
093    }
094    
095    /**
096     * Sets the dataset used by the chart and sends a 
097     * {@link PropertyChangeEvent} for the <code>dataset</code> property to all
098     * registered listeners.
099     * 
100     * @param dataset  the dataset (<code>null</code> permitted).
101     * 
102     * @see #getDataset()
103     */
104    public void setDataset(XYDataset dataset) {
105        XYPlot plot = (XYPlot) this.chart.getPlot();
106        if (plot != null) {
107            XYDataset old = plot.getDataset();
108            plot.setDataset(dataset);
109            firePropertyChange("dataset", old, dataset);
110        }
111    }
112    
113}