KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XYStepChartDemo.java
24  * --------------------
25  * (C) Copyright 2002, 2003, by Roger Studner and Contributors.
26  *
27  * Original Author: Roger Studner;
28  * Contributor(s): David Gilbert (for Object Refinery Limited);
29  *
30  * $Id: XYStepChartDemo.java,v 1.6 2003/11/28 10:57:35 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 13-May-2002 : Version 1, contributed by Roger Studner (DG);
35  * 11-Oct-2002 : Moved create method to ChartFactory class, and fixed issues reported by
36  * Checkstyle (DG);
37  *
38  */

39 package org.jfree.chart.demo;
40
41 import java.awt.BasicStroke JavaDoc;
42 import java.awt.Color JavaDoc;
43
44 import org.jfree.chart.ChartFactory;
45 import org.jfree.chart.ChartFrame;
46 import org.jfree.chart.JFreeChart;
47 import org.jfree.chart.plot.PlotOrientation;
48 import org.jfree.chart.plot.XYPlot;
49 import org.jfree.data.XYDataset;
50 import org.jfree.ui.RefineryUtilities;
51
52 /**
53  * A demonstration of the {@link XYStepRenderer} class.
54  *
55  * @author Roger Studner
56  */

57 public class XYStepChartDemo {
58
59     /** A frame for displaying the chart. */
60     private ChartFrame frame = null;
61
62     /**
63      * Displays a sample chart in its own frame.
64      */

65     private void displayChart() {
66
67         if (frame == null) {
68
69             // create a default chart based on some sample data...
70
String JavaDoc title = "LCACs in use at given time";
71             String JavaDoc xAxisLabel = "Time";
72             String JavaDoc yAxisLabel = "Number of Transports";
73
74             XYDataset data = DemoDatasetFactory.createStepXYDataset();
75
76             JFreeChart chart = ChartFactory.createXYStepChart(
77                 title,
78                 xAxisLabel, yAxisLabel,
79                 data,
80                 PlotOrientation.VERTICAL,
81                 true, // legend
82
true, // tooltips
83
false // urls
84
);
85
86             // then customise it a little...
87
chart.setBackgroundPaint(new Color JavaDoc(216, 216, 216));
88             XYPlot plot = chart.getXYPlot();
89             plot.getRenderer().setSeriesStroke(0, new BasicStroke JavaDoc(2.0f));
90             plot.getRenderer().setSeriesStroke(1, new BasicStroke JavaDoc(2.0f));
91             
92             // and present it in a frame...
93
frame = new ChartFrame("Plan Comparison", chart);
94             frame.pack();
95             RefineryUtilities.positionFrameRandomly(frame);
96             frame.show();
97
98         }
99         else {
100             frame.show();
101             frame.requestFocus();
102         }
103
104     }
105
106     // ****************************************************************************
107
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
108
// * Please note that commercial support and documentation is available from: *
109
// * *
110
// * http://www.object-refinery.com/jfreechart/support.html *
111
// * *
112
// * This is not only a great service for developers, but is a VERY IMPORTANT *
113
// * source of funding for the JFreeChart project. Please support us so that *
114
// * we can continue developing free software. *
115
// ****************************************************************************
116

117     /**
118      * The starting point for the demonstration application.
119      *
120      * @param args ignored.
121      */

122     public static void main(String JavaDoc[] args) {
123
124         XYStepChartDemo demo = new XYStepChartDemo();
125         demo.displayChart();
126
127     }
128
129 }
130
Popular Tags