KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > XYAreaChartDemo


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------
23  * AreaXYChartDemo.java
24  * --------------------
25  * (C) Copyright 2002, 2003 by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: XYAreaChartDemo.java,v 1.2 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 03-Apr-2002 : Version 1 (DG);
35  * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  * 10-Oct-2002 : Renamed AreaChartDemo --> AreaXYChartDemo (DG);
37  * 10-Jun-2003 : Modified to handle plot orientation (DG);
38  * 31-Jul-2003 : Renamed AreaXYChartDemo --> XYAreaChartDemo (DG);
39  *
40  */

41
42 package org.jfree.chart.demo;
43
44 import java.awt.Color JavaDoc;
45
46 import org.jfree.chart.ChartFactory;
47 import org.jfree.chart.ChartPanel;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.chart.axis.ValueAxis;
50 import org.jfree.chart.plot.PlotOrientation;
51 import org.jfree.chart.plot.XYPlot;
52 import org.jfree.data.XYDataset;
53 import org.jfree.data.XYSeries;
54 import org.jfree.data.XYSeriesCollection;
55 import org.jfree.ui.ApplicationFrame;
56 import org.jfree.ui.RefineryUtilities;
57
58 /**
59  * A simple demonstration application showing how to create an area chart.
60  *
61  * @author David Gilbert
62  */

63 public class XYAreaChartDemo extends ApplicationFrame {
64
65     /**
66      * Creates a new demo.
67      *
68      * @param title the frame title.
69      */

70     public XYAreaChartDemo(String JavaDoc title) {
71
72         super(title);
73
74         XYSeries series1 = new XYSeries("Random 1");
75         series1.add(new Integer JavaDoc(1), new Double JavaDoc(500.2));
76         series1.add(new Integer JavaDoc(2), new Double JavaDoc(694.1));
77         series1.add(new Integer JavaDoc(3), new Double JavaDoc(-734.4));
78         series1.add(new Integer JavaDoc(4), new Double JavaDoc(453.2));
79         series1.add(new Integer JavaDoc(5), new Double JavaDoc(500.2));
80         series1.add(new Integer JavaDoc(6), new Double JavaDoc(300.7));
81         series1.add(new Integer JavaDoc(7), new Double JavaDoc(734.4));
82         series1.add(new Integer JavaDoc(8), new Double JavaDoc(453.2));
83
84         XYSeries series2 = new XYSeries("Random 2");
85         series2.add(new Integer JavaDoc(1), new Double JavaDoc(700.2));
86         series2.add(new Integer JavaDoc(2), new Double JavaDoc(534.1));
87         series2.add(new Integer JavaDoc(3), new Double JavaDoc(323.4));
88         series2.add(new Integer JavaDoc(4), new Double JavaDoc(125.2));
89         series2.add(new Integer JavaDoc(5), new Double JavaDoc(653.2));
90         series2.add(new Integer JavaDoc(6), new Double JavaDoc(432.7));
91         series2.add(new Integer JavaDoc(7), new Double JavaDoc(564.4));
92         series2.add(new Integer JavaDoc(8), new Double JavaDoc(322.2));
93
94         XYSeriesCollection dataset = new XYSeriesCollection(series1);
95         dataset.addSeries(series2);
96         
97         JFreeChart chart = createChart(dataset);
98         
99         ChartPanel chartPanel = new ChartPanel(chart);
100         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
101         setContentPane(chartPanel);
102
103     }
104
105     /**
106      * Creates a chart.
107      *
108      * @param dataset the dataset.
109      *
110      * @return A chart.
111      */

112     private JFreeChart createChart(XYDataset dataset) {
113             
114         JFreeChart chart = ChartFactory.createXYAreaChart(
115             "XY Area Chart Demo",
116             "Domain (X)", "Range (Y)",
117             dataset,
118             PlotOrientation.VERTICAL,
119             true, // legend
120
true, // tool tips
121
false // URLs
122
);
123         
124         chart.setBackgroundPaint(Color.white);
125         
126         XYPlot plot = chart.getXYPlot();
127         //plot.setOutlinePaint(Color.black);
128
plot.setBackgroundPaint(Color.lightGray);
129         plot.setForegroundAlpha(0.65f);
130         plot.setDomainGridlinePaint(Color.white);
131         plot.setRangeGridlinePaint(Color.white);
132         
133         ValueAxis domainAxis = plot.getDomainAxis();
134         domainAxis.setTickMarkPaint(Color.black);
135         domainAxis.setLowerMargin(0.0);
136         domainAxis.setUpperMargin(0.0);
137         
138         ValueAxis rangeAxis = plot.getRangeAxis();
139         rangeAxis.setTickMarkPaint(Color.black);
140         
141         return chart;
142         
143     }
144     
145     // ****************************************************************************
146
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
147
// * Please note that commercial support and documentation is available from: *
148
// * *
149
// * http://www.object-refinery.com/jfreechart/support.html *
150
// * *
151
// * This is not only a great service for developers, but is a VERY IMPORTANT *
152
// * source of funding for the JFreeChart project. Please support us so that *
153
// * we can continue developing free software. *
154
// ****************************************************************************
155

156     /**
157      * Starting point for the demonstration application.
158      *
159      * @param args ignored.
160      */

161     public static void main(String JavaDoc[] args) {
162
163         XYAreaChartDemo demo = new XYAreaChartDemo("Area XY Chart Demo");
164         demo.pack();
165         RefineryUtilities.centerFrameOnScreen(demo);
166         demo.setVisible(true);
167
168     }
169
170 }
171
Popular Tags