KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BarChartDemo2.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: BarChartDemo2.java,v 1.2 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 14-Nov-2002 : Version 1 (DG);
35  * 11-Nov-2003 : Renamed BarChartDemo2 (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.axis.AxisLocation;
47 import org.jfree.chart.axis.NumberAxis;
48 import org.jfree.chart.plot.CategoryPlot;
49 import org.jfree.chart.plot.PlotOrientation;
50 import org.jfree.data.CategoryDataset;
51 import org.jfree.data.DatasetUtilities;
52 import org.jfree.ui.ApplicationFrame;
53 import org.jfree.ui.RefineryUtilities;
54
55 /**
56  * A simple demonstration application showing how to create a horizontal bar chart.
57  *
58  * @author David Gilbert
59  */

60 public class BarChartDemo2 extends ApplicationFrame {
61
62     /**
63      * Creates a new demo instance.
64      *
65      * @param title the frame title.
66      */

67     public BarChartDemo2(String JavaDoc title) {
68
69         super(title);
70
71         // create a dataset...
72
double[][] data = new double[][] {
73             {1.0, 43.0, 35.0, 58.0, 54.0, 77.0, 71.0, 89.0},
74             {54.0, 75.0, 63.0, 83.0, 43.0, 46.0, 27.0, 13.0},
75             {41.0, 33.0, 22.0, 34.0, 62.0, 32.0, 42.0, 34.0}
76         };
77
78         CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
79             "Series ",
80             "Factor ",
81             data
82         );
83
84         // create the chart...
85
JFreeChart chart = ChartFactory.createBarChart(
86             "Bar Chart Demo 2", // chart title
87
"Category", // domain axis label
88
"Score (%)", // range axis label
89
dataset, // data
90
PlotOrientation.HORIZONTAL,
91             true, // include legend
92
true,
93             false
94             );
95
96         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
97

98         // set the background color for the chart...
99
chart.setBackgroundPaint(Color.lightGray);
100
101         // get a reference to the plot for further customisation...
102
CategoryPlot plot = chart.getCategoryPlot();
103         plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
104         
105         // change the auto tick unit selection to integer units only...
106
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
107         rangeAxis.setRange(0.0, 100.0);
108         rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
109         
110         // OPTIONAL CUSTOMISATION COMPLETED.
111

112         // add the chart to a panel...
113
ChartPanel chartPanel = new ChartPanel(chart);
114         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
115         setContentPane(chartPanel);
116
117     }
118
119     // ****************************************************************************
120
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
121
// * Please note that commercial support and documentation is available from: *
122
// * *
123
// * http://www.object-refinery.com/jfreechart/support.html *
124
// * *
125
// * This is not only a great service for developers, but is a VERY IMPORTANT *
126
// * source of funding for the JFreeChart project. Please support us so that *
127
// * we can continue developing free software. *
128
// ****************************************************************************
129

130     /**
131      * Starting point for the demonstration application.
132      *
133      * @param args ignored.
134      */

135     public static void main(String JavaDoc[] args) {
136
137         BarChartDemo2 demo = new BarChartDemo2("Bar Chart Demo 2");
138         demo.pack();
139         RefineryUtilities.centerFrameOnScreen(demo);
140         demo.setVisible(true);
141
142     }
143
144 }
145
Popular Tags