KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Second.java
24  * -----------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited).
28  * Contributor(s): -;
29  *
30  * $Id: Second.java,v 1.7 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes (since 24-Apr-2002)
33  * ---------------------------
34  * 24-Apr-2002 : Added standard header (DG);
35  * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import org.jfree.chart.ChartFactory;
42 import org.jfree.chart.ChartFrame;
43 import org.jfree.chart.JFreeChart;
44 import org.jfree.chart.axis.ValueAxis;
45 import org.jfree.chart.plot.PlotOrientation;
46 import org.jfree.chart.plot.XYPlot;
47 import org.jfree.chart.renderer.StandardXYItemRenderer;
48 import org.jfree.chart.renderer.XYItemRenderer;
49 import org.jfree.data.XYSeries;
50 import org.jfree.data.XYSeriesCollection;
51
52 /**
53  * A simple demo.
54  *
55  * @author David Gilbert
56  */

57 public class Second {
58
59     /**
60      * Starting point for the demo.
61      *
62      * @param args ignored.
63      */

64     public static void main(String JavaDoc[] args) {
65
66         // create some data...
67
XYSeries series1 = new XYSeries("Advisory Range");
68         series1.add(new Integer JavaDoc(1200), new Integer JavaDoc(1));
69         series1.add(new Integer JavaDoc(1500), new Integer JavaDoc(1));
70
71         XYSeries series2 = new XYSeries("Normal Range");
72         series2.add(new Integer JavaDoc(2000), new Integer JavaDoc(4));
73         series2.add(new Integer JavaDoc(2300), new Integer JavaDoc(4));
74
75         XYSeries series3 = new XYSeries("Recommended");
76         series3.add(new Integer JavaDoc(2100), new Integer JavaDoc(2));
77
78         XYSeries series4 = new XYSeries("Current");
79         series4.add(new Integer JavaDoc(2400), new Integer JavaDoc(3));
80
81         XYSeriesCollection data = new XYSeriesCollection();
82         data.addSeries(series1);
83         data.addSeries(series2);
84         data.addSeries(series3);
85         data.addSeries(series4);
86
87         // create a chart...
88
JFreeChart chart = ChartFactory.createXYLineChart(
89             "My Chart",
90             "Calories",
91             "Y",
92             data,
93             PlotOrientation.VERTICAL,
94             true,
95             true,
96             false
97         );
98
99         // ****************************************************************************
100
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
101
// * Please note that commercial support and documentation is available from: *
102
// * *
103
// * http://www.object-refinery.com/jfreechart/support.html *
104
// * *
105
// * This is not only a great service for developers, but is a VERY IMPORTANT *
106
// * source of funding for the JFreeChart project. Please support us so that *
107
// * we can continue developing free software. *
108
// ****************************************************************************
109

110         XYItemRenderer renderer
111             = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES, null);
112         XYPlot plot = (XYPlot) chart.getPlot();
113         plot.setRenderer(renderer);
114         ValueAxis axis = plot.getRangeAxis();
115         axis.setTickLabelsVisible(false);
116         axis.setRange(0.0, 5.0);
117
118         // create and display a frame...
119
ChartFrame frame = new ChartFrame("Test", chart);
120         frame.pack();
121         frame.setVisible(true);
122
123     }
124
125 }
126
Popular Tags