KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XYBarChartDemo.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: XYBarChartDemo.java,v 1.3 2003/11/28 10:57:36 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 java.awt.Color JavaDoc;
44 import java.awt.GradientPaint JavaDoc;
45
46 import org.jfree.chart.ChartFactory;
47 import org.jfree.chart.ChartPanel;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.chart.axis.DateAxis;
50 import org.jfree.chart.axis.DateTickMarkPosition;
51 import org.jfree.chart.labels.TimeSeriesToolTipGenerator;
52 import org.jfree.chart.plot.PlotOrientation;
53 import org.jfree.chart.plot.XYPlot;
54 import org.jfree.chart.renderer.XYItemRenderer;
55 import org.jfree.data.time.TimeSeriesCollection;
56 import org.jfree.ui.ApplicationFrame;
57 import org.jfree.ui.RefineryUtilities;
58
59 /**
60  * A simple demonstration application showing how to create a vertical bar chart.
61  *
62  * @author David Gilbert
63  */

64 public class XYBarChartDemo extends ApplicationFrame {
65
66     /**
67      * Constructs the demo application.
68      *
69      * @param title the frame title.
70      */

71     public XYBarChartDemo(String JavaDoc title) {
72
73         super(title);
74
75         TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1();
76         data.setDomainIsPointsInTime(false);
77         JFreeChart chart = ChartFactory.createXYBarChart(
78             title,
79             "X",
80             "Y",
81             data,
82             PlotOrientation.VERTICAL,
83             true,
84             false,
85             false
86         );
87
88         // then customise it a little...
89
chart.setBackgroundPaint(new GradientPaint JavaDoc(0, 0, Color.white, 1000, 0, Color.blue));
90
91         XYItemRenderer renderer = chart.getXYPlot().getRenderer();
92         renderer.setToolTipGenerator(new TimeSeriesToolTipGenerator());
93
94         XYPlot plot = chart.getXYPlot();
95         DateAxis axis = (DateAxis) plot.getDomainAxis();
96         axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
97         
98         // add the chart to a panel...
99
ChartPanel chartPanel = new ChartPanel(chart);
100         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 300));
101         setContentPane(chartPanel);
102
103     }
104
105     // ****************************************************************************
106
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
107
// * Please note that commercial support and documentation is available from: *
108
// * *
109
// * http://www.object-refinery.com/jfreechart/support.html *
110
// * *
111
// * This is not only a great service for developers, but is a VERY IMPORTANT *
112
// * source of funding for the JFreeChart project. Please support us so that *
113
// * we can continue developing free software. *
114
// ****************************************************************************
115

116     /**
117      * Starting point for the demonstration application.
118      *
119      * @param args ignored.
120      */

121     public static void main(String JavaDoc[] args) {
122
123         XYBarChartDemo demo = new XYBarChartDemo("XY Bar Chart Demo");
124         demo.pack();
125         RefineryUtilities.centerFrameOnScreen(demo);
126         demo.setVisible(true);
127
128     }
129
130 }
131
Popular Tags