KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StackedAreaChartDemo.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: StackedAreaChartDemo.java,v 1.15 2003/11/28 10:57:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 23-Sep-2002 : Version 1 (DG);
35  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.awt.Color JavaDoc;
42
43 import org.jfree.chart.ChartFactory;
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.axis.CategoryAxis;
47 import org.jfree.chart.axis.NumberAxis;
48 import org.jfree.chart.plot.CategoryPlot;
49 import org.jfree.chart.plot.PlotOrientation;
50 import org.jfree.chart.renderer.CategoryItemRenderer;
51 import org.jfree.data.CategoryDataset;
52 import org.jfree.data.DatasetUtilities;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RefineryUtilities;
55
56 /**
57  * A simple demonstration application showing how to create a stacked area chart using data from a
58  * {@link TableDataset}.
59  *
60  * @author David Gilbert
61  */

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

69     public StackedAreaChartDemo(String JavaDoc title) {
70
71         super(title);
72
73         // create a dataset...
74
double[][] data = new double[][] {
75             {1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
76             {5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
77             {4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }};
78
79         CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);
80
81         // create the chart...
82
JFreeChart chart = ChartFactory.createStackedAreaChart(
83             "Stacked Area Chart", // chart title
84
"Category", // domain axis label
85
"Value", // range axis label
86
dataset, // data
87
PlotOrientation.VERTICAL, // orientation
88
true, // include legend
89
true,
90             false
91         );
92
93         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
94

95         // set the background color for the chart...
96
chart.setBackgroundPaint(Color.yellow);
97
98         // get a reference to the plot for further customisation...
99
CategoryPlot plot = chart.getCategoryPlot();
100         plot.setForegroundAlpha(0.5f);
101
102         CategoryAxis domainAxis = plot.getDomainAxis();
103         domainAxis.setLowerMargin(0.0);
104         domainAxis.setUpperMargin(0.0);
105
106         // change the auto tick unit selection to integer units only...
107
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
108         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
109
110         CategoryItemRenderer renderer = plot.getRenderer();
111         renderer.setItemLabelsVisible(Boolean.TRUE);
112
113         // OPTIONAL CUSTOMISATION COMPLETED.
114

115         // add the chart to a panel...
116
ChartPanel chartPanel = new ChartPanel(chart);
117         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
118
119         setContentPane(chartPanel);
120
121     }
122
123     // ****************************************************************************
124
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
125
// * Please note that commercial support and documentation is available from: *
126
// * *
127
// * http://www.object-refinery.com/jfreechart/support.html *
128
// * *
129
// * This is not only a great service for developers, but is a VERY IMPORTANT *
130
// * source of funding for the JFreeChart project. Please support us so that *
131
// * we can continue developing free software. *
132
// ****************************************************************************
133

134     /**
135      * Starting point for the demonstration application.
136      *
137      * @param args ignored.
138      */

139     public static void main(String JavaDoc[] args) {
140
141         StackedAreaChartDemo demo = new StackedAreaChartDemo("Stacked Area Chart Demo");
142         demo.pack();
143         RefineryUtilities.centerFrameOnScreen(demo);
144         demo.setVisible(true);
145
146     }
147
148 }
149
Popular Tags