KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XYBarChartDemo3.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: XYBarChartDemo3.java,v 1.4 2003/11/28 10:57:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 20-Jun-2002 : Version 1 (DG);
35  * 02-Jul-2002 : Removed unnecessary imports (DG);
36  * 24-Aug-2002 : Set preferred size for ChartPanel (DG);
37  * 11-Oct-2002 : Fixed issues reported by Checkstyle (DG);
38  * 05-Feb-2003 : Renamed VerticalXYBarChartDemo --> VerticalXYBarChartDemo3 (DG);
39  *
40  */

41
42 package org.jfree.chart.demo;
43
44 import org.jfree.chart.ChartFactory;
45 import org.jfree.chart.ChartPanel;
46 import org.jfree.chart.JFreeChart;
47 import org.jfree.chart.axis.NumberAxis;
48 import org.jfree.chart.plot.PlotOrientation;
49 import org.jfree.chart.plot.XYPlot;
50 import org.jfree.data.IntervalXYDataset;
51 import org.jfree.ui.ApplicationFrame;
52 import org.jfree.ui.RefineryUtilities;
53
54 /**
55  * A simple demonstration application showing how to create a vertical bar chart.
56  *
57  * @author David Gilbert
58  */

59 public class XYBarChartDemo3 extends ApplicationFrame {
60
61     /**
62      * Constructs the demo application.
63      *
64      * @param title the frame title.
65      */

66     public XYBarChartDemo3(String JavaDoc title) {
67
68         super(title);
69
70         // create a dataset...
71
IntervalXYDataset dataset = new SimpleIntervalXYDataset();
72
73         // create the chart...
74
JFreeChart chart = createChart(dataset);
75
76         // add the chart to a panel...
77
ChartPanel chartPanel = new ChartPanel(chart);
78         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 300));
79         setContentPane(chartPanel);
80
81     }
82
83     // ****************************************************************************
84
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
85
// * Please note that commercial support and documentation is available from: *
86
// * *
87
// * http://www.object-refinery.com/jfreechart/support.html *
88
// * *
89
// * This is not only a great service for developers, but is a VERY IMPORTANT *
90
// * source of funding for the JFreeChart project. Please support us so that *
91
// * we can continue developing free software. *
92
// ****************************************************************************
93

94     /**
95      * Creates a new chart.
96      *
97      * @param dataset the dataset.
98      *
99      * @return The chart.
100      */

101     private JFreeChart createChart(IntervalXYDataset dataset) {
102     
103         JFreeChart chart = ChartFactory.createXYBarChart(
104             "Sample", // chart title
105
"X", // domain axis label
106
"Y", // range axis label
107
dataset, // data
108
PlotOrientation.VERTICAL,
109             true, // include legend
110
true,
111             false
112         );
113
114         XYPlot plot = chart.getXYPlot();
115         plot.setDomainAxis(new NumberAxis("X"));
116         
117         return chart;
118         
119     }
120     
121     /**
122      * Starting point for the demonstration application.
123      *
124      * @param args ignored.
125      */

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