KickJava   Java API By Example, From Geeks To Geeks.

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


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  * AreaXYChartDemo2.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: XYAreaChartDemo2.java,v 1.2 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 26-Nov-2002 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import org.jfree.chart.ChartFactory;
41 import org.jfree.chart.ChartPanel;
42 import org.jfree.chart.JFreeChart;
43 import org.jfree.chart.axis.DateAxis;
44 import org.jfree.chart.axis.ValueAxis;
45 import org.jfree.chart.plot.PlotOrientation;
46 import org.jfree.chart.plot.XYPlot;
47 import org.jfree.data.XYDataset;
48 import org.jfree.data.time.Day;
49 import org.jfree.data.time.TimeSeries;
50 import org.jfree.data.time.TimeSeriesCollection;
51 import org.jfree.ui.ApplicationFrame;
52 import org.jfree.ui.RefineryUtilities;
53
54 /**
55  * A simple demonstration application showing how to create an area chart with a date axis for
56  * the domain values.
57  *
58  * @author David Gilbert
59  */

60 public class XYAreaChartDemo2 extends ApplicationFrame {
61
62     /**
63      * Creates a new demo.
64      *
65      * @param title the frame title.
66      */

67     public XYAreaChartDemo2(String JavaDoc title) {
68
69         super(title);
70
71         TimeSeries series1 = new TimeSeries("Random 1");
72         double value = 0.0;
73         Day day = new Day();
74         for (int i = 0; i < 200; i++) {
75             value = value + Math.random() - 0.5;
76             series1.add(day, value);
77             day = (Day) day.next();
78         }
79
80         TimeSeriesCollection dataset = new TimeSeriesCollection(series1);
81
82         JFreeChart chart = createChart(dataset);
83
84         ChartPanel chartPanel = new ChartPanel(chart);
85         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
86         setContentPane(chartPanel);
87
88     }
89
90     // ****************************************************************************
91
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
92
// * Please note that commercial support and documentation is available from: *
93
// * *
94
// * http://www.object-refinery.com/jfreechart/support.html *
95
// * *
96
// * This is not only a great service for developers, but is a VERY IMPORTANT *
97
// * source of funding for the JFreeChart project. Please support us so that *
98
// * we can continue developing free software. *
99
// ****************************************************************************
100

101     /**
102      * Creates a chart.
103      *
104      * @param dataset the dataset.
105      *
106      * @return The chart.
107      */

108     private JFreeChart createChart(XYDataset dataset) {
109         JFreeChart chart = ChartFactory.createXYAreaChart(
110             "XY Area Chart Demo 2",
111             "Time", "Value",
112             dataset,
113             PlotOrientation.VERTICAL,
114             true, // legend
115
true, // tool tips
116
false // URLs
117
);
118         XYPlot plot = chart.getXYPlot();
119
120         ValueAxis domainAxis = new DateAxis("Time");
121         domainAxis.setLowerMargin(0.0);
122         domainAxis.setUpperMargin(0.0);
123         plot.setDomainAxis(domainAxis);
124         plot.setForegroundAlpha(0.5f);
125         return chart;
126     }
127     
128     /**
129      * Starting point for the demonstration application.
130      *
131      * @param args ignored.
132      */

133     public static void main(String JavaDoc[] args) {
134
135         XYAreaChartDemo2 demo = new XYAreaChartDemo2("XY Area Chart Demo 2");
136         demo.pack();
137         RefineryUtilities.centerFrameOnScreen(demo);
138         demo.setVisible(true);
139
140     }
141
142 }
143
Popular Tags