KickJava   Java API By Example, From Geeks To Geeks.

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


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  * EventFrequencyDemo.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: EventFrequencyDemo.java,v 1.10 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes (from 10-Oct-2002)
33  * --------------------------
34  * 10-Oct-2002 : Added standard header and Javadocs (DG);
35  * 11-Feb-2003 : Fixed 0.9.5 bug (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.awt.Color JavaDoc;
42 import java.text.DateFormat JavaDoc;
43
44 import org.jfree.chart.ChartFactory;
45 import org.jfree.chart.ChartPanel;
46 import org.jfree.chart.JFreeChart;
47 import org.jfree.chart.StandardLegend;
48 import org.jfree.chart.axis.DateAxis;
49 import org.jfree.chart.labels.CategoryItemLabelGenerator;
50 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
51 import org.jfree.chart.plot.CategoryPlot;
52 import org.jfree.chart.plot.PlotOrientation;
53 import org.jfree.chart.renderer.CategoryItemRenderer;
54 import org.jfree.chart.renderer.LineAndShapeRenderer;
55 import org.jfree.data.DefaultCategoryDataset;
56 import org.jfree.data.time.Day;
57 import org.jfree.date.SerialDate;
58 import org.jfree.ui.ApplicationFrame;
59 import org.jfree.ui.RefineryUtilities;
60
61 /**
62  * A demo application showing how to display category data against a date axis.
63  *
64  * @author David Gilbert
65  */

66 public class EventFrequencyDemo extends ApplicationFrame {
67
68     /**
69      * Creates a new demo.
70      *
71      * @param title the frame title.
72      */

73     public EventFrequencyDemo(String JavaDoc title) {
74
75         super(title);
76
77         // create a dataset...
78
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
79
80         // initialise the data...
81
Day d1 = new Day(12, SerialDate.JUNE, 2002);
82         Day d2 = new Day(14, SerialDate.JUNE, 2002);
83         Day d3 = new Day(15, SerialDate.JUNE, 2002);
84         Day d4 = new Day(10, SerialDate.JULY, 2002);
85         Day d5 = new Day(20, SerialDate.JULY, 2002);
86         Day d6 = new Day(22, SerialDate.AUGUST, 2002);
87
88         dataset.setValue(new Long JavaDoc(d1.getMiddleMillisecond()), "Series 1", "Requirement 1");
89         dataset.setValue(new Long JavaDoc(d1.getMiddleMillisecond()), "Series 1", "Requirement 2");
90         dataset.setValue(new Long JavaDoc(d2.getMiddleMillisecond()), "Series 1", "Requirement 3");
91         dataset.setValue(new Long JavaDoc(d3.getMiddleMillisecond()), "Series 2", "Requirement 1");
92         dataset.setValue(new Long JavaDoc(d4.getMiddleMillisecond()), "Series 2", "Requirement 3");
93         dataset.setValue(new Long JavaDoc(d5.getMiddleMillisecond()), "Series 3", "Requirement 2");
94         dataset.setValue(new Long JavaDoc(d6.getMiddleMillisecond()), "Series 1", "Requirement 4");
95
96         // create the chart...
97
JFreeChart chart = ChartFactory.createBarChart(
98             "Event Frequency Demo", // title
99
"Category", // domain axis label
100
"Value", // range axis label
101
dataset, // data
102
PlotOrientation.HORIZONTAL,
103             true, // include legend
104
true, // tooltips
105
false // URLs
106
);
107
108         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
109

110         // set the background color for the chart...
111
chart.setBackgroundPaint(new Color JavaDoc(0xFF, 0xFF, 0xCC));
112
113         StandardLegend legend = (StandardLegend) chart.getLegend();
114         legend.setDisplaySeriesShapes(true);
115
116         // get a reference to the plot for further customisation...
117
CategoryPlot plot = chart.getCategoryPlot();
118         plot.setRangeAxis(new DateAxis("Date"));
119         CategoryItemLabelGenerator labelGenerator
120             = new StandardCategoryItemLabelGenerator(DateFormat.getDateInstance());
121         CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
122         renderer.setItemLabelGenerator(labelGenerator);
123         plot.setRenderer(renderer);
124                                                   
125         // ****************************************************************************
126
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
127
// * Please note that commercial support and documentation is available from: *
128
// * *
129
// * http://www.object-refinery.com/jfreechart/support.html *
130
// * *
131
// * This is not only a great service for developers, but is a VERY IMPORTANT *
132
// * source of funding for the JFreeChart project. Please support us so that *
133
// * we can continue developing free software. *
134
// ****************************************************************************
135

136         // OPTIONAL CUSTOMISATION COMPLETED.
137

138         // add the chart to a panel...
139
ChartPanel chartPanel = new ChartPanel(chart);
140         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
141         setContentPane(chartPanel);
142
143     }
144
145     /**
146      * Starting point for the demonstration application.
147      *
148      * @param args ignored.
149      */

150     public static void main(String JavaDoc[] args) {
151
152         EventFrequencyDemo demo = new EventFrequencyDemo("Event Frequency Demo");
153         demo.pack();
154         RefineryUtilities.centerFrameOnScreen(demo);
155         demo.setVisible(true);
156
157     }
158
159 }
160
Popular Tags