KickJava   Java API By Example, From Geeks To Geeks.

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


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  * HorizontalBarChartDemo3.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: BarChartDemo6.java,v 1.2 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 07-Aug-2002 : Version 1 (DG);
35  * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  * 14-Nov-2002 : Renamed HorizontalBarChartDemo2 --> HorizontalBarChartDemo3 (DG);
37  *
38  */

39
40 package org.jfree.chart.demo;
41
42 import java.awt.Color JavaDoc;
43 import java.awt.Insets JavaDoc;
44
45 import org.jfree.chart.ChartFactory;
46 import org.jfree.chart.ChartPanel;
47 import org.jfree.chart.JFreeChart;
48 import org.jfree.chart.axis.CategoryAxis;
49 import org.jfree.chart.axis.NumberAxis;
50 import org.jfree.chart.plot.CategoryPlot;
51 import org.jfree.chart.plot.PlotOrientation;
52 import org.jfree.data.DefaultCategoryDataset;
53 import org.jfree.ui.ApplicationFrame;
54 import org.jfree.ui.RefineryUtilities;
55
56 /**
57  * Another horizontal bar chart demo. This time all the extras (titles, legend and axes) are
58  * removed, to display just a single bar.
59  *
60  * @author David Gilbert
61  */

62 public class BarChartDemo6 extends ApplicationFrame {
63
64     /**
65      * Creates a new demo.
66      *
67      * @param title the frame title.
68      */

69     public BarChartDemo6(String JavaDoc title) {
70
71         super(title);
72
73         // create a dataset...
74
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
75         dataset.addValue(83.0, "First", "Factor 1");
76
77         // create the chart...
78
JFreeChart chart = ChartFactory.createBarChart(
79             null, // chart title
80
"Category", // domain axis label
81
"Score (%)", // range axis label
82
dataset, // data
83
PlotOrientation.HORIZONTAL,
84             false, // include legend
85
true,
86             false
87         );
88
89         // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
90
chart.setBackgroundPaint(Color.yellow); // not seen
91
CategoryPlot plot = chart.getCategoryPlot();
92         plot.setInsets(new Insets JavaDoc(0, 0, 0, 0));
93         plot.setRangeGridlinesVisible(false);
94         CategoryAxis domainAxis = plot.getDomainAxis();
95         domainAxis.setLowerMargin(0.20);
96         domainAxis.setUpperMargin(0.20);
97         domainAxis.setVisible(false);
98         NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
99         rangeAxis.setRange(0.0, 100.0);
100         rangeAxis.setVisible(false);
101         // OPTIONAL CUSTOMISATION COMPLETED.
102

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

121     /**
122      * Starting point for the demonstration application.
123      *
124      * @param args ignored.
125      */

126     public static void main(String JavaDoc[] args) {
127
128         BarChartDemo6 demo = new BarChartDemo6("Minimal Chart Demo");
129         demo.pack();
130         RefineryUtilities.centerFrameOnScreen(demo);
131         demo.setVisible(true);
132
133     }
134
135 }
136
Popular Tags