KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StackedBarChartDemo2.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: StackedBarChartDemo2.java,v 1.5 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 07-Nov-2002 : Version 1 (DG);
35  * 13-May-2003 : Renamed StackedHorizontalBarChartDemo --> StackedBarChartDemo2 (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import org.jfree.chart.ChartFactory;
42 import org.jfree.chart.ChartPanel;
43 import org.jfree.chart.JFreeChart;
44 import org.jfree.chart.plot.CategoryPlot;
45 import org.jfree.chart.plot.PlotOrientation;
46 import org.jfree.chart.renderer.StackedBarRenderer;
47 import org.jfree.data.CategoryDataset;
48 import org.jfree.ui.ApplicationFrame;
49 import org.jfree.ui.RefineryUtilities;
50
51 /**
52  * A simple demonstration application showing how to create a stacked bar chart
53  * using data from a {@link CategoryDataset}. This demo also has item labels displayed.
54  *
55  * @author David Gilbert
56  */

57 public class StackedBarChartDemo2 extends ApplicationFrame {
58
59     /**
60      * Creates a new demo.
61      *
62      * @param title the frame title.
63      */

64     public StackedBarChartDemo2(String JavaDoc title) {
65
66         super(title);
67         
68         CategoryDataset dataset = createDataset();
69         JFreeChart chart = createChart(dataset);
70         ChartPanel chartPanel = new ChartPanel(chart);
71         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
72         setContentPane(chartPanel);
73
74     }
75     
76     /**
77      * Creates a sample dataset.
78      *
79      * @return a sample dataset.
80      */

81     private CategoryDataset createDataset() {
82         return DemoDatasetFactory.createCategoryDataset();
83     }
84     
85     /**
86      * Creates a sample chart.
87      *
88      * @return a sample chart.
89      */

90     private JFreeChart createChart(CategoryDataset dataset) {
91         
92         JFreeChart chart = ChartFactory.createStackedBarChart(
93             "Stacked Bar Chart Demo 2",
94             "Category", // domain axis label
95
"Value", // range axis label
96
dataset, // data
97
PlotOrientation.HORIZONTAL, // the plot orientation
98
true, // include legend
99
true, // tooltips
100
false // urls
101
);
102
103         CategoryPlot plot = (CategoryPlot) chart.getPlot();
104         StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
105         renderer.setItemLabelsVisible(true);
106         
107         return chart;
108         
109     }
110
111     // ****************************************************************************
112
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
113
// * Please note that commercial support and documentation is available from: *
114
// * *
115
// * http://www.object-refinery.com/jfreechart/support.html *
116
// * *
117
// * This is not only a great service for developers, but is a VERY IMPORTANT *
118
// * source of funding for the JFreeChart project. Please support us so that *
119
// * we can continue developing free software. *
120
// ****************************************************************************
121

122     /**
123      * Starting point for the demonstration application.
124      *
125      * @param args ignored.
126      */

127     public static void main(String JavaDoc[] args) {
128
129         StackedBarChartDemo2 demo = new StackedBarChartDemo2("Stacked Bar Chart Demo 2");
130         demo.pack();
131         RefineryUtilities.centerFrameOnScreen(demo);
132         demo.setVisible(true);
133
134     }
135
136 }
137
Popular Tags