KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CombinedXYPlotDemo3.java
24  * ------------------------
25  * (C) Copyright 2003 by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited).
28  * Contributor(s): -;
29  *
30  * $Id $
31  *
32  * Changes
33  * -------
34  * 03-Jul-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.Color JavaDoc;
41 import java.awt.Font JavaDoc;
42 import java.awt.GradientPaint JavaDoc;
43
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.TextTitle;
47 import org.jfree.chart.axis.DateAxis;
48 import org.jfree.chart.axis.NumberAxis;
49 import org.jfree.chart.plot.CombinedRangeXYPlot;
50 import org.jfree.chart.plot.XYPlot;
51 import org.jfree.chart.renderer.StandardXYItemRenderer;
52 import org.jfree.chart.renderer.XYBarRenderer;
53 import org.jfree.data.MovingAverage;
54 import org.jfree.data.time.TimeSeries;
55 import org.jfree.data.time.TimeSeriesCollection;
56 import org.jfree.ui.ApplicationFrame;
57 import org.jfree.ui.RefineryUtilities;
58
59 /**
60  * A demonstration application showing how to create a combined chart using...
61  *
62  * @author David Gilbert
63  */

64 public class CombinedXYPlotDemo3 extends ApplicationFrame {
65
66     /**
67      * Constructs a new demonstration application.
68      *
69      * @param title the frame title.
70      */

71     public CombinedXYPlotDemo3(String JavaDoc title) {
72
73         super(title);
74         JFreeChart chart = createCombinedChart();
75         ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
76         panel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
77         setContentPane(panel);
78
79     }
80
81     /**
82      * Creates a combined XYPlot chart.
83      *
84      * @return the combined chart.
85      */

86     private JFreeChart createCombinedChart() {
87
88         // create a default chart based on some sample data...
89
TimeSeriesCollection dataset0 = new TimeSeriesCollection();
90         TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
91         dataset0.addSeries(eur);
92
93         TimeSeriesCollection dataset1 = new TimeSeriesCollection();
94         TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
95         dataset1.addSeries(eur);
96         dataset1.addSeries(mav);
97
98         TimeSeriesCollection dataset2 = new TimeSeriesCollection();
99         dataset2.addSeries(eur);
100
101         JFreeChart chart = null;
102
103         // make a common vertical axis for all the sub-plots
104
NumberAxis valueAxis = new NumberAxis("Value");
105         valueAxis.setAutoRangeIncludesZero(false); // override default
106

107         // make a horizontally combined plot
108
CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);
109
110         // add subplot 1...
111
XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null,
112                                      new StandardXYItemRenderer());
113         parent.add(subplot1, 1);
114
115         // add subplot 2...
116
XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null,
117                                      new StandardXYItemRenderer());
118         parent.add(subplot2, 1);
119
120         // add subplot 3...
121
XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"),
122                                      null, new XYBarRenderer(0.20));
123         parent.add(subplot3, 1);
124
125         // now make the top level JFreeChart
126
chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true);
127
128         // then customise it a little...
129
TextTitle subtitle = new TextTitle("This is a subtitle",
130                                            new Font JavaDoc("SansSerif", Font.BOLD, 12));
131         chart.addSubtitle(subtitle);
132         chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 0, 1000, Color.blue));
133         return chart;
134
135     }
136
137     // ****************************************************************************
138
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
139
// * Please note that commercial support and documentation is available from: *
140
// * *
141
// * http://www.object-refinery.com/jfreechart/support.html *
142
// * *
143
// * This is not only a great service for developers, but is a VERY IMPORTANT *
144
// * source of funding for the JFreeChart project. Please support us so that *
145
// * we can continue developing free software. *
146
// ****************************************************************************
147

148     /**
149      * Starting point for the demonstration application.
150      *
151      * @param args ignored.
152      */

153     public static void main(String JavaDoc[] args) {
154
155         CombinedXYPlotDemo3 demo = new CombinedXYPlotDemo3("Combined XY Plot Demo 3");
156         demo.pack();
157         RefineryUtilities.centerFrameOnScreen(demo);
158         demo.setVisible(true);
159
160     }
161
162 }
163
Popular Tags