KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ChartFactory


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -----------------
27  * ChartFactory.java
28  * -----------------
29  * (C) Copyright 2001-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Serge V. Grachov;
33  * Joao Guilherme Del Valle;
34  * Bill Kelemen;
35  * Jon Iles;
36  * Jelai Wang;
37  * Richard Atkinson;
38  * David Browning (for Australian Institute of Marine
39  * Science);
40  * Benoit Xhenseval;
41  *
42  * $Id: ChartFactory.java,v 1.22 2005/06/02 08:34:44 mungady Exp $
43  *
44  * Changes
45  * -------
46  * 19-Oct-2001 : Version 1, most methods transferred from JFreeChart.java (DG);
47  * 22-Oct-2001 : Added methods to create stacked bar charts (DG);
48  * Renamed DataSource.java --> Dataset.java etc. (DG);
49  * 31-Oct-2001 : Added 3D-effect vertical bar and stacked-bar charts,
50  * contributed by Serge V. Grachov (DG);
51  * 07-Nov-2001 : Added a flag to control whether or not a legend is added to
52  * the chart (DG);
53  * 17-Nov-2001 : For pie chart, changed dataset from CategoryDataset to
54  * PieDataset (DG);
55  * 30-Nov-2001 : Removed try/catch handlers from chart creation, as the
56  * exception are now RuntimeExceptions, as suggested by Joao
57  * Guilherme Del Valle (DG);
58  * 06-Dec-2001 : Added createCombinableXXXXXCharts methods (BK);
59  * 12-Dec-2001 : Added createCandlestickChart() method (DG);
60  * 13-Dec-2001 : Updated methods for charts with new renderers (DG);
61  * 08-Jan-2002 : Added import for
62  * com.jrefinery.chart.combination.CombinedChart (DG);
63  * 31-Jan-2002 : Changed the createCombinableVerticalXYBarChart() method to use
64  * renderer (DG);
65  * 06-Feb-2002 : Added new method createWindPlot() (DG);
66  * 23-Apr-2002 : Updates to the chart and plot constructor API (DG);
67  * 21-May-2002 : Added new method createAreaChart() (JI);
68  * 06-Jun-2002 : Added new method createGanttChart() (DG);
69  * 11-Jun-2002 : Renamed createHorizontalStackedBarChart()
70  * --> createStackedHorizontalBarChart() for consistency (DG);
71  * 06-Aug-2002 : Updated Javadoc comments (DG);
72  * 21-Aug-2002 : Added createPieChart(CategoryDataset) method (DG);
73  * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
74  * 09-Oct-2002 : Added methods including tooltips and URL flags (DG);
75  * 06-Nov-2002 : Moved renderers into a separate package (DG);
76  * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG);
77  * 21-Mar-2003 : Incorporated HorizontalCategoryAxis3D, see bug id 685501 (DG);
78  * 13-May-2003 : Merged some horizontal and vertical methods (DG);
79  * 24-May-2003 : Added support for timeline in createHighLowChart (BK);
80  * 07-Jul-2003 : Added createHistogram() method contributed by Jelai Wang (DG);
81  * 27-Jul-2003 : Added createStackedAreaXYChart() method (RA);
82  * 05-Aug-2003 : added new method createBoxAndWhiskerChart (DB);
83  * 08-Sep-2003 : Changed ValueAxis API (DG);
84  * 07-Oct-2003 : Added stepped area XY chart contributed by Matthias Rose (DG);
85  * 06-Nov-2003 : Added createWaterfallChart() method (DG);
86  * 20-Nov-2003 : Set rendering order for 3D bar charts to fix overlapping
87  * problems (DG);
88  * 25-Nov-2003 : Added createWaferMapChart() method (DG);
89  * 23-Dec-2003 : Renamed createPie3DChart() --> createPieChart3D for
90  * consistency (DG);
91  * 20-Jan-2004 : Added createPolarChart() method (DG);
92  * 28-Jan-2004 : Fixed bug (882890) with axis range in
93  * createStackedXYAreaChart() method (DG);
94  * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator (DG);
95  * 11-Mar-2004 : Updated for pie chart changes (DG);
96  * 27-Apr-2004 : Added new createPieChart() method contributed by Benoit
97  * Xhenseval (see RFE 942195) (DG);
98  * 11-May-2004 : Split StandardCategoryItemLabelGenerator
99  * --> StandardCategoryToolTipGenerator and
100  * StandardCategoryLabelGenerator (DG);
101  * 06-Jan-2005 : Removed deprecated methods (DG);
102  * 27-Jan-2005 : Added new constructor to LineAndShapeRenderer (DG);
103  * 28-Feb-2005 : Added docs to createBubbleChart() method (DG);
104  * 17-Mar-2005 : Added createRingPlot() method (DG);
105  * 21-Apr-2005 : Replaced Insets with RectangleInsets (DG);
106  *
107  */

108
109 package org.jfree.chart;
110
111 import java.awt.Color JavaDoc;
112 import java.awt.Font JavaDoc;
113 import java.text.DateFormat JavaDoc;
114 import java.text.NumberFormat JavaDoc;
115 import java.util.Iterator JavaDoc;
116 import java.util.List JavaDoc;
117
118 import org.jfree.chart.axis.CategoryAxis;
119 import org.jfree.chart.axis.CategoryAxis3D;
120 import org.jfree.chart.axis.DateAxis;
121 import org.jfree.chart.axis.NumberAxis;
122 import org.jfree.chart.axis.NumberAxis3D;
123 import org.jfree.chart.axis.Timeline;
124 import org.jfree.chart.axis.ValueAxis;
125 import org.jfree.chart.labels.HighLowItemLabelGenerator;
126 import org.jfree.chart.labels.IntervalCategoryToolTipGenerator;
127 import org.jfree.chart.labels.ItemLabelAnchor;
128 import org.jfree.chart.labels.ItemLabelPosition;
129 import org.jfree.chart.labels.PieToolTipGenerator;
130 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
131 import org.jfree.chart.labels.StandardPieItemLabelGenerator;
132 import org.jfree.chart.labels.StandardXYToolTipGenerator;
133 import org.jfree.chart.labels.StandardXYZToolTipGenerator;
134 import org.jfree.chart.labels.XYToolTipGenerator;
135 import org.jfree.chart.plot.CategoryPlot;
136 import org.jfree.chart.plot.Marker;
137 import org.jfree.chart.plot.MultiplePiePlot;
138 import org.jfree.chart.plot.PiePlot;
139 import org.jfree.chart.plot.PiePlot3D;
140 import org.jfree.chart.plot.PlotOrientation;
141 import org.jfree.chart.plot.PolarPlot;
142 import org.jfree.chart.plot.RingPlot;
143 import org.jfree.chart.plot.ValueMarker;
144 import org.jfree.chart.plot.WaferMapPlot;
145 import org.jfree.chart.plot.XYPlot;
146 import org.jfree.chart.renderer.DefaultPolarItemRenderer;
147 import org.jfree.chart.renderer.WaferMapRenderer;
148 import org.jfree.chart.renderer.category.AreaRenderer;
149 import org.jfree.chart.renderer.category.BarRenderer;
150 import org.jfree.chart.renderer.category.BarRenderer3D;
151 import org.jfree.chart.renderer.category.CategoryItemRenderer;
152 import org.jfree.chart.renderer.category.GanttRenderer;
153 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
154 import org.jfree.chart.renderer.category.LineRenderer3D;
155 import org.jfree.chart.renderer.category.StackedAreaRenderer;
156 import org.jfree.chart.renderer.category.StackedBarRenderer;
157 import org.jfree.chart.renderer.category.StackedBarRenderer3D;
158 import org.jfree.chart.renderer.category.WaterfallBarRenderer;
159 import org.jfree.chart.renderer.xy.CandlestickRenderer;
160 import org.jfree.chart.renderer.xy.HighLowRenderer;
161 import org.jfree.chart.renderer.xy.SignalRenderer;
162 import org.jfree.chart.renderer.xy.StackedXYAreaRenderer;
163 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
164 import org.jfree.chart.renderer.xy.WindItemRenderer;
165 import org.jfree.chart.renderer.xy.XYAreaRenderer;
166 import org.jfree.chart.renderer.xy.XYBarRenderer;
167 import org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer;
168 import org.jfree.chart.renderer.xy.XYBubbleRenderer;
169 import org.jfree.chart.renderer.xy.XYItemRenderer;
170 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
171 import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
172 import org.jfree.chart.renderer.xy.XYStepRenderer;
173 import org.jfree.chart.title.TextTitle;
174 import org.jfree.chart.urls.PieURLGenerator;
175 import org.jfree.chart.urls.StandardCategoryURLGenerator;
176 import org.jfree.chart.urls.StandardPieURLGenerator;
177 import org.jfree.chart.urls.StandardXYURLGenerator;
178 import org.jfree.chart.urls.StandardXYZURLGenerator;
179 import org.jfree.chart.urls.XYURLGenerator;
180 import org.jfree.data.category.CategoryDataset;
181 import org.jfree.data.category.IntervalCategoryDataset;
182 import org.jfree.data.general.DefaultPieDataset;
183 import org.jfree.data.general.PieDataset;
184 import org.jfree.data.general.WaferMapDataset;
185 import org.jfree.data.statistics.BoxAndWhiskerXYDataset;
186 import org.jfree.data.xy.IntervalXYDataset;
187 import org.jfree.data.xy.OHLCDataset;
188 import org.jfree.data.xy.SignalsDataset;
189 import org.jfree.data.xy.TableXYDataset;
190 import org.jfree.data.xy.WindDataset;
191 import org.jfree.data.xy.XYDataset;
192 import org.jfree.data.xy.XYZDataset;
193 import org.jfree.ui.Layer;
194 import org.jfree.ui.RectangleEdge;
195 import org.jfree.ui.RectangleInsets;
196 import org.jfree.ui.TextAnchor;
197 import org.jfree.util.SortOrder;
198 import org.jfree.util.TableOrder;
199
200 /**
201  * A collection of utility methods for creating some standard charts with
202  * JFreeChart.
203  */

204 public abstract class ChartFactory {
205
206     /**
207      * Creates a pie chart with default settings.
208      * <P>
209      * The chart object returned by this method uses a {@link PiePlot} instance
210      * as the plot.
211      *
212      * @param title the chart title (<code>null</code> permitted).
213      * @param dataset the dataset for the chart (<code>null</code> permitted).
214      * @param legend a flag specifying whether or not a legend is required.
215      * @param tooltips configure chart to generate tool tips?
216      * @param urls configure chart to generate URLs?
217      *
218      * @return A pie chart.
219      */

220     public static JFreeChart createPieChart(String JavaDoc title,
221                                             PieDataset dataset,
222                                             boolean legend,
223                                             boolean tooltips,
224                                             boolean urls) {
225
226         PiePlot plot = new PiePlot(dataset);
227         plot.setLabelGenerator(new StandardPieItemLabelGenerator());
228         plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
229         if (tooltips) {
230             plot.setToolTipGenerator(
231                 new StandardPieItemLabelGenerator(
232                     StandardPieItemLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT
233                 )
234             );
235         }
236         if (urls) {
237             plot.setURLGenerator(new StandardPieURLGenerator());
238         }
239         return new JFreeChart(
240             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
241         );
242
243     }
244
245     /**
246      * Creates a pie chart with default settings that compares 2 datasets.
247      * The colour of each section will be determined by the move from the value
248      * for the same key in <code>previousDataset</code>. ie if value1 > value2
249      * then the section will be in green (unless <code>greenForIncrease</code>
250      * is <code>false</code>, in which case it would be <code>red</code>).
251      * Each section can have a shade of red or green as the difference can be
252      * tailored between 0% (black) and percentDiffForMaxScale% (bright
253      * red/green).
254      * <p>
255      * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a
256      * difference of 5% will have a half shade of red/green, a difference of
257      * 10% or more will have a maximum shade/brightness of red/green.
258      * <P>
259      * The chart object returned by this method uses a {@link PiePlot} instance
260      * as the plot.
261      * <p>
262      * Written by <a HREF="mailto:opensource@objectlab.co.uk">Benoit
263      * Xhenseval</a>.
264      *
265      * @param title the chart title (<code>null</code> permitted).
266      * @param dataset the dataset for the chart (<code>null</code> permitted).
267      * @param previousDataset the dataset for the last run, this will be used
268      * to compare each key in the dataset
269      * @param percentDiffForMaxScale scale goes from bright red/green to black,
270      * percentDiffForMaxScale indicate the change
271      * required to reach top scale.
272      * @param greenForIncrease an increase since previousDataset will be
273      * displayed in green (decrease red) if true.
274      * @param legend a flag specifying whether or not a legend is required.
275      * @param tooltips configure chart to generate tool tips?
276      * @param urls configure chart to generate URLs?
277      * @param subTitle displays a subtitle with colour scheme if true
278      * @param showDifference create a new dataset that will show the %
279      * difference between the two datasets.
280      *
281      * @return A pie chart.
282      */

283     public static JFreeChart createPieChart(String JavaDoc title,
284                                             PieDataset dataset,
285                                             PieDataset previousDataset,
286                                             int percentDiffForMaxScale,
287                                             boolean greenForIncrease,
288                                             boolean legend,
289                                             boolean tooltips,
290                                             boolean urls,
291                                             boolean subTitle,
292                                             boolean showDifference) {
293
294         PiePlot plot = new PiePlot(dataset);
295         plot.setLabelGenerator(new StandardPieItemLabelGenerator());
296         plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
297
298         if (tooltips) {
299             plot.setToolTipGenerator(
300                 new StandardPieItemLabelGenerator(
301                     StandardPieItemLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT
302                 )
303             );
304         }
305         if (urls) {
306             plot.setURLGenerator(new StandardPieURLGenerator());
307         }
308
309         List JavaDoc keys = dataset.getKeys();
310         DefaultPieDataset series = null;
311         if (showDifference) {
312             series = new DefaultPieDataset();
313         }
314
315         double colorPerPercent = 255.0 / percentDiffForMaxScale;
316         for (Iterator JavaDoc it = keys.iterator(); it.hasNext();) {
317             Comparable JavaDoc key = (Comparable JavaDoc) it.next();
318             Number JavaDoc newValue = dataset.getValue(key);
319             Number JavaDoc oldValue = previousDataset.getValue(key);
320             int section = dataset.getIndex(key);
321
322             if (oldValue == null) {
323                 if (greenForIncrease) {
324                     plot.setSectionPaint(section, Color.green);
325                 }
326                 else {
327                     plot.setSectionPaint(section, Color.red);
328                 }
329                 if (showDifference) {
330                     series.setValue(key + " (+100%)", newValue);
331                 }
332             }
333             else {
334                 double percentChange = (newValue.doubleValue()
335                         / oldValue.doubleValue() - 1.0) * 100.0;
336                 double shade
337                     = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
338                     : Math.abs(percentChange) * colorPerPercent);
339                 if (greenForIncrease
340                         && newValue.doubleValue() > oldValue.doubleValue()
341                         || !greenForIncrease && newValue.doubleValue()
342                         < oldValue.doubleValue()) {
343                     plot.setSectionPaint(section, new Color JavaDoc(0, (int) shade, 0));
344                 }
345                 else {
346                     plot.setSectionPaint(section, new Color JavaDoc((int) shade, 0, 0));
347                 }
348                 if (showDifference) {
349                     series.setValue(
350                         key + " (" + (percentChange >= 0 ? "+" : "")
351                         + NumberFormat.getPercentInstance().format(
352                                 percentChange / 100.0) + ")", newValue
353                     );
354                 }
355             }
356         }
357
358         if (showDifference) {
359             plot.setDataset(series);
360         }
361
362         JFreeChart chart = new JFreeChart(
363             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
364         );
365
366         if (subTitle) {
367             TextTitle subtitle = null;
368             subtitle = new TextTitle(
369                 "Bright " + (greenForIncrease ? "red" : "green")
370                 + "=change >=-" + percentDiffForMaxScale + "%, Bright "
371                 + (!greenForIncrease ? "red" : "green") + "=change >=+"
372                 + percentDiffForMaxScale + "%",
373                 new Font JavaDoc("SansSerif", Font.PLAIN, 10)
374             );
375             chart.addSubtitle(subtitle);
376         }
377
378         return chart;
379     }
380
381     /**
382      * Creates a ring chart with default settings.
383      * <P>
384      * The chart object returned by this method uses a {@link RingPlot}
385      * instance as the plot.
386      *
387      * @param title the chart title (<code>null</code> permitted).
388      * @param dataset the dataset for the chart (<code>null</code> permitted).
389      * @param legend a flag specifying whether or not a legend is required.
390      * @param tooltips configure chart to generate tool tips?
391      * @param urls configure chart to generate URLs?
392      *
393      * @return A pie chart.
394      */

395     public static JFreeChart createRingChart(String JavaDoc title,
396                                              PieDataset dataset,
397                                              boolean legend,
398                                              boolean tooltips,
399                                              boolean urls) {
400
401         RingPlot plot = new RingPlot(dataset);
402         plot.setLabelGenerator(new StandardPieItemLabelGenerator());
403         plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
404         if (tooltips) {
405             plot.setToolTipGenerator(
406                 new StandardPieItemLabelGenerator(
407                     StandardPieItemLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT
408                 )
409             );
410         }
411         if (urls) {
412             plot.setURLGenerator(new StandardPieURLGenerator());
413         }
414         return new JFreeChart(
415             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
416         );
417
418     }
419
420     /**
421      * Creates a chart that displays multiple pie plots. The chart object
422      * returned by this method uses a {@link MultiplePiePlot} instance as the
423      * plot.
424      *
425      * @param title the chart title (<code>null</code> permitted).
426      * @param dataset the dataset (<code>null</code> permitted).
427      * @param order the order that the data is extracted (by row or by column)
428      * (<code>null</code> not permitted).
429      * @param legend include a legend?
430      * @param tooltips generate tooltips?
431      * @param urls generate URLs?
432      *
433      * @return A chart.
434      */

435     public static JFreeChart createMultiplePieChart(String JavaDoc title,
436                                                     CategoryDataset dataset,
437                                                     TableOrder order,
438                                                     boolean legend,
439                                                     boolean tooltips,
440                                                     boolean urls) {
441
442         if (order == null) {
443             throw new IllegalArgumentException JavaDoc("Null 'order' argument.");
444         }
445         MultiplePiePlot plot = new MultiplePiePlot(dataset);
446         plot.setDataExtractOrder(order);
447         plot.setBackgroundPaint(null);
448         plot.setOutlineStroke(null);
449
450         if (tooltips) {
451             PieToolTipGenerator tooltipGenerator
452                 = new StandardPieItemLabelGenerator();
453             PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
454             pp.setToolTipGenerator(tooltipGenerator);
455         }
456
457         if (urls) {
458             PieURLGenerator urlGenerator = new StandardPieURLGenerator();
459             PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
460             pp.setURLGenerator(urlGenerator);
461         }
462
463         JFreeChart chart = new JFreeChart(
464             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
465         );
466
467         return chart;
468
469     }
470
471     /**
472      * Creates a 3D pie chart using the specified dataset. The chart object
473      * returned by this method uses a {@link PiePlot3D} instance as the
474      * plot.
475      *
476      * @param title the chart title (<code>null</code> permitted).
477      * @param dataset the dataset for the chart (<code>null</code> permitted).
478      * @param legend a flag specifying whether or not a legend is required.
479      * @param tooltips configure chart to generate tool tips?
480      * @param urls configure chart to generate URLs?
481      *
482      * @return A pie chart.
483      */

484     public static JFreeChart createPieChart3D(String JavaDoc title,
485                                               PieDataset dataset,
486                                               boolean legend,
487                                               boolean tooltips,
488                                               boolean urls) {
489
490         PiePlot3D plot = new PiePlot3D(dataset);
491         plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
492         if (tooltips) {
493             plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
494         }
495         if (urls) {
496             plot.setURLGenerator(new StandardPieURLGenerator());
497         }
498         return new JFreeChart(
499             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
500         );
501
502     }
503
504     /**
505      * Creates a chart that displays multiple pie plots. The chart object
506      * returned by this method uses a {@link MultiplePiePlot} instance as the
507      * plot.
508      *
509      * @param title the chart title (<code>null</code> permitted).
510      * @param dataset the dataset (<code>null</code> permitted).
511      * @param order the order that the data is extracted (by row or by column)
512      * (<code>null</code> not permitted).
513      * @param legend include a legend?
514      * @param tooltips generate tooltips?
515      * @param urls generate URLs?
516      *
517      * @return A chart.
518      */

519     public static JFreeChart createMultiplePieChart3D(String JavaDoc title,
520                                                       CategoryDataset dataset,
521                                                       TableOrder order,
522                                                       boolean legend,
523                                                       boolean tooltips,
524                                                       boolean urls) {
525
526         if (order == null) {
527             throw new IllegalArgumentException JavaDoc("Null 'order' argument.");
528         }
529         MultiplePiePlot plot = new MultiplePiePlot(dataset);
530         plot.setDataExtractOrder(order);
531         plot.setBackgroundPaint(null);
532         plot.setOutlineStroke(null);
533
534         JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
535         TextTitle seriesTitle = new TextTitle(
536             "Series Title", new Font JavaDoc("SansSerif", Font.BOLD, 12)
537         );
538         seriesTitle.setPosition(RectangleEdge.BOTTOM);
539         pieChart.setTitle(seriesTitle);
540         pieChart.removeLegend();
541         pieChart.setBackgroundPaint(null);
542         plot.setPieChart(pieChart);
543
544         if (tooltips) {
545             PieToolTipGenerator tooltipGenerator
546                 = new StandardPieItemLabelGenerator();
547             PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
548             pp.setToolTipGenerator(tooltipGenerator);
549         }
550
551         if (urls) {
552             PieURLGenerator urlGenerator = new StandardPieURLGenerator();
553             PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
554             pp.setURLGenerator(urlGenerator);
555         }
556
557         JFreeChart chart = new JFreeChart(
558             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
559         );
560
561         return chart;
562
563     }
564
565     /**
566      * Creates a bar chart. The chart object returned by this method uses a
567      * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
568      * for the domain axis, a {@link NumberAxis} as the range axis, and a
569      * {@link BarRenderer} as the renderer.
570      *
571      * @param title the chart title (<code>null</code> permitted).
572      * @param categoryAxisLabel the label for the category axis
573      * (<code>null</code> permitted).
574      * @param valueAxisLabel the label for the value axis
575      * (<code>null</code> permitted).
576      * @param dataset the dataset for the chart (<code>null</code> permitted).
577      * @param orientation the plot orientation (horizontal or vertical)
578      * (<code>null</code> not permitted).
579      * @param legend a flag specifying whether or not a legend is required.
580      * @param tooltips configure chart to generate tool tips?
581      * @param urls configure chart to generate URLs?
582      *
583      * @return A bar chart.
584      */

585     public static JFreeChart createBarChart(String JavaDoc title,
586                                             String JavaDoc categoryAxisLabel,
587                                             String JavaDoc valueAxisLabel,
588                                             CategoryDataset dataset,
589                                             PlotOrientation orientation,
590                                             boolean legend,
591                                             boolean tooltips,
592                                             boolean urls) {
593
594         if (orientation == null) {
595             throw new IllegalArgumentException JavaDoc("Null 'orientation' argument.");
596         }
597         CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
598         ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
599
600         BarRenderer renderer = new BarRenderer();
601         if (orientation == PlotOrientation.HORIZONTAL) {
602             ItemLabelPosition position1 = new ItemLabelPosition(
603                 ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT
604             );
605             renderer.setPositiveItemLabelPosition(position1);
606             ItemLabelPosition position2 = new ItemLabelPosition(
607                 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT
608             );
609             renderer.setNegativeItemLabelPosition(position2);
610          }
611         else if (orientation == PlotOrientation.VERTICAL) {
612             ItemLabelPosition position1 = new ItemLabelPosition(
613                 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER
614             );
615             renderer.setPositiveItemLabelPosition(position1);
616             ItemLabelPosition position2 = new ItemLabelPosition(
617                 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER
618             );
619             renderer.setNegativeItemLabelPosition(position2);
620         }
621         if (tooltips) {
622             renderer.setBaseToolTipGenerator(
623                 new StandardCategoryToolTipGenerator()
624             );
625         }
626         if (urls) {
627             renderer.setBaseItemURLGenerator(
628                 new StandardCategoryURLGenerator()
629             );
630         }
631
632         CategoryPlot plot = new CategoryPlot(
633             dataset, categoryAxis, valueAxis, renderer
634         );
635         plot.setOrientation(orientation);
636         JFreeChart chart = new JFreeChart(
637             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
638         );
639
640         return chart;
641
642     }
643
644     /**
645      * Creates a stacked bar chart with default settings. The chart object
646      * returned by this method uses a {@link CategoryPlot} instance as the
647      * plot, with a {@link CategoryAxis} for the domain axis, a
648      * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer}
649      * as the renderer.
650      *
651      * @param title the chart title (<code>null</code> permitted).
652      * @param domainAxisLabel the label for the category axis
653      * (<code>null</code> permitted).
654      * @param rangeAxisLabel the label for the value axis
655      * (<code>null</code> permitted).
656      * @param dataset the dataset for the chart (<code>null</code> permitted).
657      * @param orientation the orientation of the chart (horizontal or
658      * vertical) (<code>null</code> not permitted).
659      * @param legend a flag specifying whether or not a legend is required.
660      * @param tooltips configure chart to generate tool tips?
661      * @param urls configure chart to generate URLs?
662      *
663      * @return A stacked bar chart.
664      */

665     public static JFreeChart createStackedBarChart(String JavaDoc title,
666                                                    String JavaDoc domainAxisLabel,
667                                                    String JavaDoc rangeAxisLabel,
668                                                    CategoryDataset dataset,
669                                                    PlotOrientation orientation,
670                                                    boolean legend,
671                                                    boolean tooltips,
672                                                    boolean urls) {
673
674         if (orientation == null) {
675             throw new IllegalArgumentException JavaDoc("Null 'orientation' argument.");
676         }
677
678         CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
679         ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);
680
681         StackedBarRenderer renderer = new StackedBarRenderer();
682         if (tooltips) {
683             renderer.setBaseToolTipGenerator(
684                 new StandardCategoryToolTipGenerator()
685             );
686         }
687         if (urls) {
688             renderer.setBaseItemURLGenerator(
689                 new StandardCategoryURLGenerator()
690             );
691         }
692
693         CategoryPlot plot = new CategoryPlot(
694             dataset, categoryAxis, valueAxis, renderer
695         );
696         plot.setOrientation(orientation);
697         JFreeChart chart = new JFreeChart(
698             title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
699         );
700
701         return chart;
702
703     }
704
705     /**
706      * Creates a bar chart with a 3D effect. The chart object returned by this
707      * method uses a {@link CategoryPlot} instance as the plot, with a
708      * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as
709      * the range axis, and a {@link BarRenderer3D} as the renderer.
710      *
711      * @param title the chart title (<code>null</code> permitted).
712      * @param categoryAxisLabel the label for the category axis
713      * (<code>null</code> permitted).
714      * @param valueAxisLabel the label for the value axis (<code>null</code>
715      * permitted).
716      * @param dataset the dataset for the chart (<code>null</code> permitted).
717      * @param orientation the plot orientation (horizontal or vertical)
718      * (<code>null</code> not permitted).
719      * @param legend a flag specifying whether or not a legend is required.
720      * @param tooltips configure chart to generate tool tips?
721      * @param urls configure chart to generate URLs?
722      *
723      * @return A bar chart with a 3D effect.
724      */

725     public static JFreeChart createBarChart3D(String JavaDoc title,
726                                               String JavaDoc categoryAxisLabel,
727                                               String JavaDoc valueAxisLabel,
728                                               CategoryDataset dataset,
729                                               PlotOrientation orientation,
730                                               boolean legend,
731                                               boolean tooltips,
732                                               boolean urls) {
733
734         if (orientation == null) {
735             throw new IllegalArgumentException JavaDoc("Null 'orientation' argument.");
736         }
737         CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
738         ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);
739
740         BarRenderer3D renderer = new BarRenderer3D();
741         if (too