KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XYBarChartDemo2.java
24  * --------------------
25  * (C) Copyright 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: XYBarChartDemo2.java,v 1.3 2003/11/28 10:57:35 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  *
39  */

40
41 package org.jfree.chart.demo;
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.DateAxis;
47 import org.jfree.chart.plot.PlotOrientation;
48 import org.jfree.chart.plot.XYPlot;
49 import org.jfree.chart.renderer.ClusteredXYBarRenderer;
50 import org.jfree.data.IntervalXYDataset;
51 import org.jfree.data.time.Day;
52 import org.jfree.data.time.TimeSeries;
53 import org.jfree.data.time.TimeSeriesCollection;
54 import org.jfree.ui.ApplicationFrame;
55 import org.jfree.ui.RefineryUtilities;
56
57 /**
58  * A simple demonstration application showing how to create a vertical bar chart.
59  *
60  * @author David Gilbert
61  */

62 public class XYBarChartDemo2 extends ApplicationFrame {
63
64     /**
65      * Constructs the demo application.
66      *
67      * @param title the frame title.
68      */

69     public XYBarChartDemo2(String JavaDoc title) {
70
71         super(title);
72
73         // create a dataset...
74
TimeSeries series1 = new TimeSeries("Series 1", Day.class);
75         series1.add(new Day(1, 1, 2003), 54.3);
76         series1.add(new Day(2, 1, 2003), 20.3);
77         series1.add(new Day(3, 1, 2003), 43.4);
78         series1.add(new Day(4, 1, 2003), -12.0);
79
80         TimeSeries series2 = new TimeSeries("Series 2", Day.class);
81         series2.add(new Day(1, 1, 2003), 8.0);
82         series2.add(new Day(2, 1, 2003), 16.0);
83         series2.add(new Day(3, 1, 2003), 21.0);
84         series2.add(new Day(4, 1, 2003), 5.0);
85
86         TimeSeriesCollection data = new TimeSeriesCollection();
87         data.setDomainIsPointsInTime(false);
88         data.addSeries(series1);
89         data.addSeries(series2);
90
91         JFreeChart chart = createChart(data);
92         
93         // add the chart to a panel...
94
ChartPanel chartPanel = new ChartPanel(chart);
95         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 300));
96         setContentPane(chartPanel);
97
98     }
99
100     // ****************************************************************************
101
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
102
// * Please note that commercial support and documentation is available from: *
103
// * *
104
// * http://www.object-refinery.com/jfreechart/support.html *
105
// * *
106
// * This is not only a great service for developers, but is a VERY IMPORTANT *
107
// * source of funding for the JFreeChart project. Please support us so that *
108
// * we can continue developing free software. *
109
// ****************************************************************************
110

111     /**
112      * Creates a chart.
113      *
114      * @param dataset the dataset.
115      *
116      * @return The chart.
117      */

118     private JFreeChart createChart(IntervalXYDataset dataset) {
119         JFreeChart chart = ChartFactory.createXYBarChart(
120             "XY Bar Chart Demo 2", // chart title
121
"X", // domain axis label
122
"Y", // range axis label
123
dataset, // data
124
PlotOrientation.HORIZONTAL,
125             true, // include legend
126
true,
127             false
128         );
129
130         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
131
XYPlot plot = chart.getXYPlot();
132         plot.setDomainAxis(new DateAxis("Date"));
133         plot.setRenderer(new ClusteredXYBarRenderer());
134         // OPTIONAL CUSTOMISATION COMPLETED.
135
return chart;
136     }
137
138     /**
139      * Starting point for the demonstration application.
140      *
141      * @param args ignored.
142      */

143     public static void main(String JavaDoc[] args) {
144
145         XYBarChartDemo2 demo = new XYBarChartDemo2("XY Bar Chart Demo 2");
146         demo.pack();
147         RefineryUtilities.centerFrameOnScreen(demo);
148         demo.setVisible(true);
149
150     }
151
152 }
153
Popular Tags