KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MinMaxCategoryPlotDemo.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: MinMaxCategoryPlotDemo.java,v 1.6 2003/11/28 10:57:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 08-Aug-2002 : Demo for a renderer contributed by Tomer Peretz (DG);
35  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.awt.Color JavaDoc;
42
43 import org.jfree.chart.ChartFactory;
44 import org.jfree.chart.ChartPanel;
45 import org.jfree.chart.JFreeChart;
46 import org.jfree.chart.plot.CategoryPlot;
47 import org.jfree.chart.plot.PlotOrientation;
48 import org.jfree.chart.renderer.MinMaxCategoryRenderer;
49 import org.jfree.data.DefaultCategoryDataset;
50 import org.jfree.ui.ApplicationFrame;
51 import org.jfree.ui.RefineryUtilities;
52
53 /**
54  * A simple demonstration application showing how to create a min/max category plot.
55  *
56  * @author David Gilbert
57  */

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

65     public MinMaxCategoryPlotDemo(String JavaDoc title) {
66
67         super(title);
68
69         // create a dataset...
70
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
71         dataset.addValue(1.0, "First", "Category 1");
72         dataset.addValue(4.0, "First", "Category 2");
73         dataset.addValue(3.0, "First", "Category 3");
74         dataset.addValue(5.0, "First", "Category 4");
75         dataset.addValue(5.0, "First", "Category 5");
76         dataset.addValue(7.0, "First", "Category 6");
77         dataset.addValue(7.0, "First", "Category 7");
78         dataset.addValue(8.0, "First", "Category 8");
79         dataset.addValue(5.0, "Second", "Category 1");
80         dataset.addValue(7.0, "Second", "Category 2");
81         dataset.addValue(6.0, "Second", "Category 3");
82         dataset.addValue(8.0, "Second", "Category 4");
83         dataset.addValue(4.0, "Second", "Category 5");
84         dataset.addValue(4.0, "Second", "Category 6");
85         dataset.addValue(2.0, "Second", "Category 7");
86         dataset.addValue(1.0, "Second", "Category 8");
87         dataset.addValue(4.0, "Third", "Category 1");
88         dataset.addValue(3.0, "Third", "Category 2");
89         dataset.addValue(2.0, "Third", "Category 3");
90         dataset.addValue(3.0, "Third", "Category 4");
91         dataset.addValue(6.0, "Third", "Category 5");
92         dataset.addValue(3.0, "Third", "Category 6");
93         dataset.addValue(4.0, "Third", "Category 7");
94         dataset.addValue(3.0, "Third", "Category 8");
95
96         // create the chart...
97
JFreeChart chart = ChartFactory.createBarChart(
98             "Min/Max Category Plot", // chart title
99
"Category", // domain axis label
100
"Value", // range axis label
101
dataset, // data
102
PlotOrientation.VERTICAL,
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(Color.yellow);
112
113         // get a reference to the plot for further customisation...
114
CategoryPlot plot = chart.getCategoryPlot();
115         plot.setRenderer(new MinMaxCategoryRenderer());
116         // OPTIONAL CUSTOMISATION COMPLETED.
117

118         // add the chart to a panel...
119
ChartPanel chartPanel = new ChartPanel(chart);
120         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
121         setContentPane(chartPanel);
122
123     }
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    /**
137      * Starting point for the demonstration application.
138      *
139      * @param args ignored.
140      */

141     public static void main(String JavaDoc[] args) {
142
143         MinMaxCategoryPlotDemo demo = new MinMaxCategoryPlotDemo("Min/Max Category Chart Demo");
144         demo.pack();
145         RefineryUtilities.centerFrameOnScreen(demo);
146         demo.setVisible(true);
147
148     }
149
150 }
151
Popular Tags