KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CombinedCategoryPlotDemo1.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: CombinedCategoryPlotDemo1.java,v 1.7 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 16-May-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.Font JavaDoc;
41
42 import org.jfree.chart.ChartPanel;
43 import org.jfree.chart.JFreeChart;
44 import org.jfree.chart.Legend;
45 import org.jfree.chart.axis.CategoryAxis;
46 import org.jfree.chart.axis.NumberAxis;
47 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
48 import org.jfree.chart.plot.CategoryPlot;
49 import org.jfree.chart.plot.CombinedDomainCategoryPlot;
50 import org.jfree.chart.renderer.BarRenderer;
51 import org.jfree.chart.renderer.LineAndShapeRenderer;
52 import org.jfree.data.CategoryDataset;
53 import org.jfree.data.DefaultCategoryDataset;
54 import org.jfree.ui.ApplicationFrame;
55 import org.jfree.ui.RefineryUtilities;
56
57 /**
58  * A demo for the {@link CombinedDomainCategoryPlot} class.
59  *
60  * @author David Gilbert
61  */

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

69     public CombinedCategoryPlotDemo1(String JavaDoc title) {
70
71         super(title);
72
73         // add the chart to a panel...
74
ChartPanel chartPanel = new ChartPanel(createChart());
75         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
76         setContentPane(chartPanel);
77
78     }
79
80     /**
81      * Creates a dataset.
82      *
83      * @return A dataset.
84      */

85     public CategoryDataset createDataset1() {
86
87         DefaultCategoryDataset result = new DefaultCategoryDataset();
88
89         // row keys...
90
String JavaDoc series1 = "First";
91         String JavaDoc series2 = "Second";
92
93         // column keys...
94
String JavaDoc type1 = "Type 1";
95         String JavaDoc type2 = "Type 2";
96         String JavaDoc type3 = "Type 3";
97         String JavaDoc type4 = "Type 4";
98         String JavaDoc type5 = "Type 5";
99         String JavaDoc type6 = "Type 6";
100         String JavaDoc type7 = "Type 7";
101         String JavaDoc type8 = "Type 8";
102
103         result.addValue(1.0, series1, type1);
104         result.addValue(4.0, series1, type2);
105         result.addValue(3.0, series1, type3);
106         result.addValue(5.0, series1, type4);
107         result.addValue(5.0, series1, type5);
108         result.addValue(7.0, series1, type6);
109         result.addValue(7.0, series1, type7);
110         result.addValue(8.0, series1, type8);
111
112         result.addValue(5.0, series2, type1);
113         result.addValue(7.0, series2, type2);
114         result.addValue(6.0, series2, type3);
115         result.addValue(8.0, series2, type4);
116         result.addValue(4.0, series2, type5);
117         result.addValue(4.0, series2, type6);
118         result.addValue(2.0, series2, type7);
119         result.addValue(1.0, series2, type8);
120
121         return result;
122
123     }
124
125     /**
126      * Creates a dataset.
127      *
128      * @return A dataset.
129      */

130     public CategoryDataset createDataset2() {
131
132         DefaultCategoryDataset result = new DefaultCategoryDataset();
133
134         // row keys...
135
String JavaDoc series1 = "Third";
136         String JavaDoc series2 = "Fourth";
137
138         // column keys...
139
String JavaDoc type1 = "Type 1";
140         String JavaDoc type2 = "Type 2";
141         String JavaDoc type3 = "Type 3";
142         String JavaDoc type4 = "Type 4";
143         String JavaDoc type5 = "Type 5";
144         String JavaDoc type6 = "Type 6";
145         String JavaDoc type7 = "Type 7";
146         String JavaDoc type8 = "Type 8";
147
148         result.addValue(11.0, series1, type1);
149         result.addValue(14.0, series1, type2);
150         result.addValue(13.0, series1, type3);
151         result.addValue(15.0, series1, type4);
152         result.addValue(15.0, series1, type5);
153         result.addValue(17.0, series1, type6);
154         result.addValue(17.0, series1, type7);
155         result.addValue(18.0, series1, type8);
156
157         result.addValue(15.0, series2, type1);
158         result.addValue(17.0, series2, type2);
159         result.addValue(16.0, series2, type3);
160         result.addValue(18.0, series2, type4);
161         result.addValue(14.0, series2, type5);
162         result.addValue(14.0, series2, type6);
163         result.addValue(12.0, series2, type7);
164         result.addValue(11.0, series2, type8);
165
166         return result;
167
168     }
169
170     // ****************************************************************************
171
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
172
// * Please note that commercial support and documentation is available from: *
173
// * *
174
// * http://www.object-refinery.com/jfreechart/support.html *
175
// * *
176
// * This is not only a great service for developers, but is a VERY IMPORTANT *
177
// * source of funding for the JFreeChart project. Please support us so that *
178
// * we can continue developing free software. *
179
// ****************************************************************************
180

181     /**
182      * Creates a chart.
183      *
184      * @return A chart.
185      */

186     private JFreeChart createChart() {
187
188         CategoryDataset dataset1 = createDataset1();
189         NumberAxis rangeAxis1 = new NumberAxis("Value");
190         rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
191         LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
192         renderer1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
193         CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
194         subplot1.setDomainGridlinesVisible(true);
195         
196         CategoryDataset dataset2 = createDataset2();
197         NumberAxis rangeAxis2 = new NumberAxis("Value");
198         rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
199         BarRenderer renderer2 = new BarRenderer();
200         renderer2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
201         CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
202         subplot2.setDomainGridlinesVisible(true);
203
204         CategoryAxis domainAxis = new CategoryAxis("Category");
205         CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
206         plot.add(subplot1, 2);
207         plot.add(subplot2, 1);
208         
209         JFreeChart result = new JFreeChart(
210             "Combined Domain Category Plot Demo",
211             new Font JavaDoc("SansSerif", Font.BOLD, 12),
212             plot,
213             true
214         );
215         result.getLegend().setAnchor(Legend.SOUTH);
216         return result;
217
218     }
219
220     /**
221      * Starting point for the demonstration application.
222      *
223      * @param args ignored.
224      */

225     public static void main(String JavaDoc[] args) {
226
227         String JavaDoc title = "Combined Category Plot Demo 1";
228         CombinedCategoryPlotDemo1 demo = new CombinedCategoryPlotDemo1(title);
229         demo.pack();
230         RefineryUtilities.centerFrameOnScreen(demo);
231         demo.setVisible(true);
232
233     }
234
235 }
236
Popular Tags