001 /* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006 *
007 * Project Info: http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022 * USA.
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025 * in the United States and other countries.]
026 *
027 * -----------------
028 * ChartFactory.java
029 * -----------------
030 * (C) Copyright 2001-2007, by Object Refinery Limited and Contributors.
031 *
032 * Original Author: David Gilbert (for Object Refinery Limited);
033 * Contributor(s): Serge V. Grachov;
034 * Joao Guilherme Del Valle;
035 * Bill Kelemen;
036 * Jon Iles;
037 * Jelai Wang;
038 * Richard Atkinson;
039 * David Browning (for Australian Institute of Marine
040 * Science);
041 * Benoit Xhenseval;
042 *
043 * $Id: ChartFactory.java,v 1.22.2.11 2007/06/11 13:36:54 mungady Exp $
044 *
045 * Changes
046 * -------
047 * 19-Oct-2001 : Version 1, most methods transferred from JFreeChart.java (DG);
048 * 22-Oct-2001 : Added methods to create stacked bar charts (DG);
049 * Renamed DataSource.java --> Dataset.java etc. (DG);
050 * 31-Oct-2001 : Added 3D-effect vertical bar and stacked-bar charts,
051 * contributed by Serge V. Grachov (DG);
052 * 07-Nov-2001 : Added a flag to control whether or not a legend is added to
053 * the chart (DG);
054 * 17-Nov-2001 : For pie chart, changed dataset from CategoryDataset to
055 * PieDataset (DG);
056 * 30-Nov-2001 : Removed try/catch handlers from chart creation, as the
057 * exception are now RuntimeExceptions, as suggested by Joao
058 * Guilherme Del Valle (DG);
059 * 06-Dec-2001 : Added createCombinableXXXXXCharts methods (BK);
060 * 12-Dec-2001 : Added createCandlestickChart() method (DG);
061 * 13-Dec-2001 : Updated methods for charts with new renderers (DG);
062 * 08-Jan-2002 : Added import for
063 * com.jrefinery.chart.combination.CombinedChart (DG);
064 * 31-Jan-2002 : Changed the createCombinableVerticalXYBarChart() method to use
065 * renderer (DG);
066 * 06-Feb-2002 : Added new method createWindPlot() (DG);
067 * 23-Apr-2002 : Updates to the chart and plot constructor API (DG);
068 * 21-May-2002 : Added new method createAreaChart() (JI);
069 * 06-Jun-2002 : Added new method createGanttChart() (DG);
070 * 11-Jun-2002 : Renamed createHorizontalStackedBarChart()
071 * --> createStackedHorizontalBarChart() for consistency (DG);
072 * 06-Aug-2002 : Updated Javadoc comments (DG);
073 * 21-Aug-2002 : Added createPieChart(CategoryDataset) method (DG);
074 * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
075 * 09-Oct-2002 : Added methods including tooltips and URL flags (DG);
076 * 06-Nov-2002 : Moved renderers into a separate package (DG);
077 * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG);
078 * 21-Mar-2003 : Incorporated HorizontalCategoryAxis3D, see bug id 685501 (DG);
079 * 13-May-2003 : Merged some horizontal and vertical methods (DG);
080 * 24-May-2003 : Added support for timeline in createHighLowChart (BK);
081 * 07-Jul-2003 : Added createHistogram() method contributed by Jelai Wang (DG);
082 * 27-Jul-2003 : Added createStackedAreaXYChart() method (RA);
083 * 05-Aug-2003 : added new method createBoxAndWhiskerChart (DB);
084 * 08-Sep-2003 : Changed ValueAxis API (DG);
085 * 07-Oct-2003 : Added stepped area XY chart contributed by Matthias Rose (DG);
086 * 06-Nov-2003 : Added createWaterfallChart() method (DG);
087 * 20-Nov-2003 : Set rendering order for 3D bar charts to fix overlapping
088 * problems (DG);
089 * 25-Nov-2003 : Added createWaferMapChart() method (DG);
090 * 23-Dec-2003 : Renamed createPie3DChart() --> createPieChart3D for
091 * consistency (DG);
092 * 20-Jan-2004 : Added createPolarChart() method (DG);
093 * 28-Jan-2004 : Fixed bug (882890) with axis range in
094 * createStackedXYAreaChart() method (DG);
095 * 25-Feb-2004 : Renamed XYToolTipGenerator --> XYItemLabelGenerator (DG);
096 * 11-Mar-2004 : Updated for pie chart changes (DG);
097 * 27-Apr-2004 : Added new createPieChart() method contributed by Benoit
098 * Xhenseval (see RFE 942195) (DG);
099 * 11-May-2004 : Split StandardCategoryItemLabelGenerator
100 * --> StandardCategoryToolTipGenerator and
101 * StandardCategoryLabelGenerator (DG);
102 * 06-Jan-2005 : Removed deprecated methods (DG);
103 * 27-Jan-2005 : Added new constructor to LineAndShapeRenderer (DG);
104 * 28-Feb-2005 : Added docs to createBubbleChart() method (DG);
105 * 17-Mar-2005 : Added createRingPlot() method (DG);
106 * 21-Apr-2005 : Replaced Insets with RectangleInsets (DG);
107 * 29-Nov-2005 : Removed signal chart (DG);
108 * ------------- JFREECHART 1.0.x ---------------------------------------------
109 * 26-Jan-2006 : Corrected API docs for createScatterPlot() (DG);
110 * 23-Aug-2006 : Modified createStackedXYAreaChart() to use
111 * StackedXYAreaRenderer2, because StackedXYAreaRenderer doesn't
112 * handle negative values (DG);
113 * 27-Sep-2006 : Update createPieChart() method for deprecated code (DG);
114 * 29-Nov-2006 : Update createXYBarChart() to use a time based tool tip
115 * generator is a DateAxis is requested (DG);
116 * 17-Jan-2007 : Added createBoxAndWhiskerChart() method from patch 1603937
117 * submitted by Darren Jung (DG);
118 *
119 */
120
121 package org.jfree.chart;
122
123 import java.awt.Color;
124 import java.awt.Font;
125 import java.text.DateFormat;
126 import java.text.NumberFormat;
127 import java.util.Iterator;
128 import java.util.List;
129
130 import org.jfree.chart.axis.CategoryAxis;
131 import org.jfree.chart.axis.CategoryAxis3D;
132 import org.jfree.chart.axis.DateAxis;
133 import org.jfree.chart.axis.NumberAxis;
134 import org.jfree.chart.axis.NumberAxis3D;
135 import org.jfree.chart.axis.Timeline;
136 import org.jfree.chart.axis.ValueAxis;
137 import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
138 import org.jfree.chart.labels.HighLowItemLabelGenerator;
139 import org.jfree.chart.labels.IntervalCategoryToolTipGenerator;
140 import org.jfree.chart.labels.ItemLabelAnchor;
141 import org.jfree.chart.labels.ItemLabelPosition;
142 import org.jfree.chart.labels.PieToolTipGenerator;
143 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
144 import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
145 import org.jfree.chart.labels.StandardPieToolTipGenerator;
146 import org.jfree.chart.labels.StandardXYToolTipGenerator;
147 import org.jfree.chart.labels.StandardXYZToolTipGenerator;
148 import org.jfree.chart.labels.XYToolTipGenerator;
149 import org.jfree.chart.plot.CategoryPlot;
150 import org.jfree.chart.plot.Marker;
151 import org.jfree.chart.plot.MultiplePiePlot;
152 import org.jfree.chart.plot.PiePlot;
153 import org.jfree.chart.plot.PiePlot3D;
154 import org.jfree.chart.plot.PlotOrientation;
155 import org.jfree.chart.plot.PolarPlot;
156 import org.jfree.chart.plot.RingPlot;
157 import org.jfree.chart.plot.ValueMarker;
158 import org.jfree.chart.plot.WaferMapPlot;
159 import org.jfree.chart.plot.XYPlot;
160 import org.jfree.chart.renderer.DefaultPolarItemRenderer;
161 import org.jfree.chart.renderer.WaferMapRenderer;
162 import org.jfree.chart.renderer.category.AreaRenderer;
163 import org.jfree.chart.renderer.category.BarRenderer;
164 import org.jfree.chart.renderer.category.BarRenderer3D;
165 import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
166 import org.jfree.chart.renderer.category.CategoryItemRenderer;
167 import org.jfree.chart.renderer.category.GanttRenderer;
168 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
169 import org.jfree.chart.renderer.category.LineRenderer3D;
170 import org.jfree.chart.renderer.category.StackedAreaRenderer;
171 import org.jfree.chart.renderer.category.StackedBarRenderer;
172 import org.jfree.chart.renderer.category.StackedBarRenderer3D;
173 import org.jfree.chart.renderer.category.WaterfallBarRenderer;
174 import org.jfree.chart.renderer.xy.CandlestickRenderer;
175 import org.jfree.chart.renderer.xy.HighLowRenderer;
176 import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2;
177 import org.jfree.chart.renderer.xy.WindItemRenderer;
178 import org.jfree.chart.renderer.xy.XYAreaRenderer;
179 import org.jfree.chart.renderer.xy.XYBarRenderer;
180 import org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer;
181 import org.jfree.chart.renderer.xy.XYBubbleRenderer;
182 import org.jfree.chart.renderer.xy.XYItemRenderer;
183 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
184 import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
185 import org.jfree.chart.renderer.xy.XYStepRenderer;
186 import org.jfree.chart.title.TextTitle;
187 import org.jfree.chart.urls.PieURLGenerator;
188 import org.jfree.chart.urls.StandardCategoryURLGenerator;
189 import org.jfree.chart.urls.StandardPieURLGenerator;
190 import org.jfree.chart.urls.StandardXYURLGenerator;
191 import org.jfree.chart.urls.StandardXYZURLGenerator;
192 import org.jfree.chart.urls.XYURLGenerator;
193 import org.jfree.data.category.CategoryDataset;
194 import org.jfree.data.category.IntervalCategoryDataset;
195 import org.jfree.data.general.DefaultPieDataset;
196 import org.jfree.data.general.PieDataset;
197 import org.jfree.data.general.WaferMapDataset;
198 import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
199 import org.jfree.data.statistics.BoxAndWhiskerXYDataset;
200 import org.jfree.data.xy.IntervalXYDataset;
201 import org.jfree.data.xy.OHLCDataset;
202 import org.jfree.data.xy.TableXYDataset;
203 import org.jfree.data.xy.WindDataset;
204 import org.jfree.data.xy.XYDataset;
205 import org.jfree.data.xy.XYZDataset;
206 import org.jfree.ui.Layer;
207 import org.jfree.ui.RectangleEdge;
208 import org.jfree.ui.RectangleInsets;
209 import org.jfree.ui.TextAnchor;
210 import org.jfree.util.SortOrder;
211 import org.jfree.util.TableOrder;
212
213 /**
214 * A collection of utility methods for creating some standard charts with
215 * JFreeChart.
216 */
217 public abstract class ChartFactory {
218
219 /**
220 * Creates a pie chart with default settings.
221 * <P>
222 * The chart object returned by this method uses a {@link PiePlot} instance
223 * as the plot.
224 *
225 * @param title the chart title (<code>null</code> permitted).
226 * @param dataset the dataset for the chart (<code>null</code> permitted).
227 * @param legend a flag specifying whether or not a legend is required.
228 * @param tooltips configure chart to generate tool tips?
229 * @param urls configure chart to generate URLs?
230 *
231 * @return A pie chart.
232 */
233 public static JFreeChart createPieChart(String title,
234 PieDataset dataset,
235 boolean legend,
236 boolean tooltips,
237 boolean urls) {
238
239 PiePlot plot = new PiePlot(dataset);
240 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
241 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
242 if (tooltips) {
243 plot.setToolTipGenerator(new StandardPieToolTipGenerator(
244 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT));
245 }
246 if (urls) {
247 plot.setURLGenerator(new StandardPieURLGenerator());
248 }
249 return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot,
250 legend);
251
252 }
253
254 /**
255 * Creates a pie chart with default settings that compares 2 datasets.
256 * The colour of each section will be determined by the move from the value
257 * for the same key in <code>previousDataset</code>. ie if value1 > value2
258 * then the section will be in green (unless <code>greenForIncrease</code>
259 * is <code>false</code>, in which case it would be <code>red</code>).
260 * Each section can have a shade of red or green as the difference can be
261 * tailored between 0% (black) and percentDiffForMaxScale% (bright
262 * red/green).
263 * <p>
264 * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a
265 * difference of 5% will have a half shade of red/green, a difference of
266 * 10% or more will have a maximum shade/brightness of red/green.
267 * <P>
268 * The chart object returned by this method uses a {@link PiePlot} instance
269 * as the plot.
270 * <p>
271 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
272 * Xhenseval</a>.
273 *
274 * @param title the chart title (<code>null</code> permitted).
275 * @param dataset the dataset for the chart (<code>null</code> permitted).
276 * @param previousDataset the dataset for the last run, this will be used
277 * to compare each key in the dataset
278 * @param percentDiffForMaxScale scale goes from bright red/green to black,
279 * percentDiffForMaxScale indicate the change
280 * required to reach top scale.
281 * @param greenForIncrease an increase since previousDataset will be
282 * displayed in green (decrease red) if true.
283 * @param legend a flag specifying whether or not a legend is required.
284 * @param tooltips configure chart to generate tool tips?
285 * @param urls configure chart to generate URLs?
286 * @param subTitle displays a subtitle with colour scheme if true
287 * @param showDifference create a new dataset that will show the %
288 * difference between the two datasets.
289 *
290 * @return A pie chart.
291 */
292 public static JFreeChart createPieChart(String title,
293 PieDataset dataset,
294 PieDataset previousDataset,
295 int percentDiffForMaxScale,
296 boolean greenForIncrease,
297 boolean legend,
298 boolean tooltips,
299 boolean urls,
300 boolean subTitle,
301 boolean showDifference) {
302
303 PiePlot plot = new PiePlot(dataset);
304 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
305 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
306
307 if (tooltips) {
308 plot.setToolTipGenerator(new StandardPieToolTipGenerator(
309 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT));
310 }
311 if (urls) {
312 plot.setURLGenerator(new StandardPieURLGenerator());
313 }
314
315 List keys = dataset.getKeys();
316 DefaultPieDataset series = null;
317 if (showDifference) {
318 series = new DefaultPieDataset();
319 }
320
321 double colorPerPercent = 255.0 / percentDiffForMaxScale;
322 for (Iterator it = keys.iterator(); it.hasNext();) {
323 Comparable key = (Comparable) it.next();
324 Number newValue = dataset.getValue(key);
325 Number oldValue = previousDataset.getValue(key);
326
327 if (oldValue == null) {
328 if (greenForIncrease) {
329 plot.setSectionPaint(key, Color.green);
330 }
331 else {
332 plot.setSectionPaint(key, Color.red);
333 }
334 if (showDifference) {
335 series.setValue(key + " (+100%)", newValue);
336 }
337 }
338 else {
339 double percentChange = (newValue.doubleValue()
340 / oldValue.doubleValue() - 1.0) * 100.0;
341 double shade
342 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
343 : Math.abs(percentChange) * colorPerPercent);
344 if (greenForIncrease
345 && newValue.doubleValue() > oldValue.doubleValue()
346 || !greenForIncrease && newValue.doubleValue()
347 < oldValue.doubleValue()) {
348 plot.setSectionPaint(key, new Color(0, (int) shade, 0));
349 }
350 else {
351 plot.setSectionPaint(key, new Color((int) shade, 0, 0));
352 }
353 if (showDifference) {
354 series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
355 + NumberFormat.getPercentInstance().format(
356 percentChange / 100.0) + ")", newValue);
357 }
358 }
359 }
360
361 if (showDifference) {
362 plot.setDataset(series);
363 }
364
365 JFreeChart chart = new JFreeChart(
366 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend
367 );
368
369 if (subTitle) {
370 TextTitle subtitle = null;
371 subtitle = new TextTitle("Bright " + (greenForIncrease ? "red"
372 : "green") + "=change >=-" + percentDiffForMaxScale
373 + "%, Bright " + (!greenForIncrease ? "red" : "green")
374 + "=change >=+" + percentDiffForMaxScale + "%",
375 new Font("SansSerif", Font.PLAIN, 10));
376 chart.addSubtitle(subtitle);
377 }
378
379 return chart;
380 }
381
382 /**
383 * Creates a ring chart with default settings.
384 * <P>
385 * The chart object returned by this method uses a {@link RingPlot}
386 * instance as the plot.
387 *
388 * @param title the chart title (<code>null</code> permitted).
389 * @param dataset the dataset for the chart (<code>null</code> permitted).
390 * @param legend a flag specifying whether or not a legend is required.
391 * @param tooltips configure chart to generate tool tips?
392 * @param urls configure chart to generate URLs?
393 *
394 * @return A pie chart.
395 */
396 public static JFreeChart createRingChart(String title,
397 PieDataset dataset,
398 boolean legend,
399 boolean tooltips,
400 boolean urls) {
401
402 RingPlot plot = new RingPlot(dataset);
403 plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
404 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
405 if (tooltips) {
406 plot.setToolTipGenerator(new StandardPieToolTipGenerator(
407 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT));
408 }
409 if (urls) {
410 plot.setURLGenerator(new StandardPieURLGenerator());
411 }
412 return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot,
413 legend);
414
415 }
416
417 /**
418 * Creates a chart that displays multiple pie plots. The chart object
419 * returned by this method uses a {@link MultiplePiePlot} instance as the
420 * plot.
421 *
422 * @param title the chart title (<code>null</code> permitted).
423 * @param dataset the dataset (<code>null</code> permitted).
424 * @param order the order that the data is extracted (by row or by column)
425 * (<code>null</code> not permitted).
426 * @param legend include a legend?
427 * @param tooltips generate tooltips?
428 * @param urls generate URLs?
429 *
430 * @return A chart.
431 */
432 public static JFreeChart createMultiplePieChart(String title,
433 CategoryDataset dataset,
434 TableOrder order,
435 boolean legend,
436 boolean tooltips,
437 boolean urls) {
438
439 if (order == null) {
440 throw new IllegalArgumentException("Null 'order' argument.");
441 }
442 MultiplePiePlot plot = new MultiplePiePlot(dataset);
443 plot.setDataExtractOrder(order);
444 plot.setBackgroundPaint(null);
445 plot.setOutlineStroke(null);
446
447 if (tooltips) {
448 PieToolTipGenerator tooltipGenerator
449 = new StandardPieToolTipGenerator();
450 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
451 pp.setToolTipGenerator(tooltipGenerator);
452 }
453
454 if (urls) {
455 PieURLGenerator urlGenerator = new StandardPieURLGenerator();
456 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
457 pp.setURLGenerator(urlGenerator);
458 }
459
460 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
461 plot, legend);
462
463 return chart;
464
465 }
466
467 /**
468 * Creates a 3D pie chart using the specified dataset. The chart object
469 * returned by this method uses a {@link PiePlot3D} instance as the
470 * plot.
471 *
472 * @param title the chart title (<code>null</code> permitted).
473 * @param dataset the dataset for the chart (<code>null</code> permitted).
474 * @param legend a flag specifying whether or not a legend is required.
475 * @param tooltips configure chart to generate tool tips?
476 * @param urls configure chart to generate URLs?
477 *
478 * @return A pie chart.
479 */
480 public static JFreeChart createPieChart3D(String title,
481 PieDataset dataset,
482 boolean legend,
483 boolean tooltips,
484 boolean urls) {
485
486 PiePlot3D plot = new PiePlot3D(dataset);
487 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
488 if (tooltips) {
489 plot.setToolTipGenerator(new StandardPieToolTipGenerator());
490 }
491 if (urls) {
492 plot.setURLGenerator(new StandardPieURLGenerator());
493 }
494 return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot,
495 legend);
496
497 }
498
499 /**
500 * Creates a chart that displays multiple pie plots. The chart object
501 * returned by this method uses a {@link MultiplePiePlot} instance as the
502 * plot.
503 *
504 * @param title the chart title (<code>null</code> permitted).
505 * @param dataset the dataset (<code>null</code> permitted).
506 * @param order the order that the data is extracted (by row or by column)
507 * (<code>null</code> not permitted).
508 * @param legend include a legend?
509 * @param tooltips generate tooltips?
510 * @param urls generate URLs?
511 *
512 * @return A chart.
513 */
514 public static JFreeChart createMultiplePieChart3D(String title,
515 CategoryDataset dataset,
516 TableOrder order,
517 boolean legend,
518 boolean tooltips,
519 boolean urls) {
520
521 if (order == null) {
522 throw new IllegalArgumentException("Null 'order' argument.");
523 }
524 MultiplePiePlot plot = new MultiplePiePlot(dataset);
525 plot.setDataExtractOrder(order);
526 plot.setBackgroundPaint(null);
527 plot.setOutlineStroke(null);
528
529 JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
530 TextTitle seriesTitle = new TextTitle("Series Title",
531 new Font("SansSerif", Font.BOLD, 12));
532 seriesTitle.setPosition(RectangleEdge.BOTTOM);
533 pieChart.setTitle(seriesTitle);
534 pieChart.removeLegend();
535 pieChart.setBackgroundPaint(null);
536 plot.setPieChart(pieChart);
537
538 if (tooltips) {
539 PieToolTipGenerator tooltipGenerator
540 = new StandardPieToolTipGenerator();
541 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
542 pp.setToolTipGenerator(tooltipGenerator);
543 }
544
545 if (urls) {
546 PieURLGenerator urlGenerator = new StandardPieURLGenerator();
547 PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
548 pp.setURLGenerator(urlGenerator);
549 }
550
551 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
552 plot, legend);
553
554 return chart;
555
556 }
557
558 /**
559 * Creates a bar chart. The chart object returned by this method uses a
560 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
561 * for the domain axis, a {@link NumberAxis} as the range axis, and a
562 * {@link BarRenderer} as the renderer.
563 *
564 * @param title the chart title (<code>null</code> permitted).
565 * @param categoryAxisLabel the label for the category axis
566 * (<code>null</code> permitted).
567 * @param valueAxisLabel the label for the value axis
568 * (<code>null</code> permitted).
569 * @param dataset the dataset for the chart (<code>null</code> permitted).
570 * @param orientation the plot orientation (horizontal or vertical)
571 * (<code>null</code> not permitted).
572 * @param legend a flag specifying whether or not a legend is required.
573 * @param tooltips configure chart to generate tool tips?
574 * @param urls configure chart to generate URLs?
575 *
576 * @return A bar chart.
577 */
578 public static JFreeChart createBarChart(String title,
579 String categoryAxisLabel,
580 String valueAxisLabel,
581 CategoryDataset dataset,
582 PlotOrientation orientation,
583 boolean legend,
584 boolean tooltips,
585 boolean urls) {
586
587 if (orientation == null) {
588 throw new IllegalArgumentException("Null 'orientation' argument.");
589 }
590 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
591 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
592
593 BarRenderer renderer = new BarRenderer();
594 if (orientation == PlotOrientation.HORIZONTAL) {
595 ItemLabelPosition position1 = new ItemLabelPosition(
596 ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
597 renderer.setBasePositiveItemLabelPosition(position1);
598 ItemLabelPosition position2 = new ItemLabelPosition(
599 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
600 renderer.setBaseNegativeItemLabelPosition(position2);
601 }
602 else if (orientation == PlotOrientation.VERTICAL) {
603 ItemLabelPosition position1 = new ItemLabelPosition(
604 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
605 renderer.setBasePositiveItemLabelPosition(position1);
606 ItemLabelPosition position2 = new ItemLabelPosition(
607 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
608 renderer.setBaseNegativeItemLabelPosition(position2);
609 }
610 if (tooltips) {
611 renderer.setBaseToolTipGenerator(
612 new StandardCategoryToolTipGenerator());
613 }
614 if (urls) {
615 renderer.setBaseItemURLGenerator(
616 new StandardCategoryURLGenerator());
617 }
618
619 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
620 renderer);
621 plot.setOrientation(orientation);
622 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
623 plot, legend);
624
625 return chart;
626
627 }
628
629 /**
630 * Creates a stacked bar chart with default settings. The chart object
631 * returned by this method uses a {@link CategoryPlot} instance as the
632 * plot, with a {@link CategoryAxis} for the domain axis, a
633 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer}
634 * as the renderer.
635 *
636 * @param title the chart title (<code>null</code> permitted).
637 * @param domainAxisLabel the label for the category axis
638 * (<code>null</code> permitted).
639 * @param rangeAxisLabel the label for the value axis
640 * (<code>null</code> permitted).
641 * @param dataset the dataset for the chart (<code>null</code> permitted).
642 * @param orientation the orientation of the chart (horizontal or
643 * vertical) (<code>null</code> not permitted).
644 * @param legend a flag specifying whether or not a legend is required.
645 * @param tooltips configure chart to generate tool tips?
646 * @param urls configure chart to generate URLs?
647 *
648 * @return A stacked bar chart.
649 */
650 public static JFreeChart createStackedBarChart(String title,
651 String domainAxisLabel,
652 String rangeAxisLabel,
653 CategoryDataset dataset,
654 PlotOrientation orientation,
655 boolean legend,
656 boolean tooltips,
657 boolean urls) {
658
659 if (orientation == null) {
660 throw new IllegalArgumentException("Null 'orientation' argument.");
661 }
662
663 CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
664 ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);
665
666 StackedBarRenderer renderer = new StackedBarRenderer();
667 if (tooltips) {
668 renderer.setBaseToolTipGenerator(
669 new StandardCategoryToolTipGenerator());
670 }
671 if (urls) {
672 renderer.setBaseItemURLGenerator(
673 new StandardCategoryURLGenerator());
674 }
675
676 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
677 renderer);
678 plot.setOrientation(orientation);
679 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
680 plot, legend);
681
682 return chart;
683
684 }
685
686 /**
687 * Creates a bar chart with a 3D effect. The chart object returned by this
688 * method uses a {@link CategoryPlot} instance as the plot, with a
689 * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as
690 * the range axis, and a {@link BarRenderer3D} as the renderer.
691 *
692 * @param title the chart title (<code>null</code> permitted).
693 * @param categoryAxisLabel the label for the category axis
694 * (<code>null</code> permitted).
695 * @param valueAxisLabel the label for the value axis (<code>null</code>
696 * permitted).
697 * @param dataset the dataset for the chart (<code>null</code> permitted).
698 * @param orientation the plot orientation (horizontal or vertical)
699 * (<code>null</code> not permitted).
700 * @param legend a flag specifying whether or not a legend is required.
701 * @param tooltips configure chart to generate tool tips?
702 * @param urls configure chart to generate URLs?
703 *
704 * @return A bar chart with a 3D effect.
705 */
706 public static JFreeChart createBarChart3D(String title,
707 String categoryAxisLabel,
708 String valueAxisLabel,
709 CategoryDataset dataset,
710 PlotOrientation orientation,
711 boolean legend,
712 boolean tooltips,
713 boolean urls) {
714
715 if (orientation == null) {
716 throw new IllegalArgumentException("Null 'orientation' argument.");
717 }
718 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
719 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);
720
721 BarRenderer3D renderer = new BarRenderer3D();
722 if (tooltips) {
723 renderer.setBaseToolTipGenerator(
724 new StandardCategoryToolTipGenerator());
725 }
726 if (urls) {
727 renderer.setBaseItemURLGenerator(
728 new StandardCategoryURLGenerator());
729 }
730
731 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
732 renderer);
733 plot.setOrientation(orientation);
734 if (orientation == PlotOrientation.HORIZONTAL) {
735 // change rendering order to ensure that bar overlapping is the
736 // right way around
737 plot.setRowRenderingOrder(SortOrder.DESCENDING);
738 plot.setColumnRenderingOrder(SortOrder.DESCENDING);
739 }
740 plot.setForegroundAlpha(0.75f);
741
742 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
743 plot, legend);
744
745 return chart;
746
747 }
748
749 /**
750 * Creates a stacked bar chart with a 3D effect and default settings. The
751 * chart object returned by this method uses a {@link CategoryPlot}
752 * instance as the plot, with a {@link CategoryAxis3D} for the domain axis,
753 * a {@link NumberAxis3D} as the range axis, and a
754 * {@link StackedBarRenderer3D} as the renderer.
755 *
756 * @param title the chart title (<code>null</code> permitted).
757 * @param categoryAxisLabel the label for the category axis
758 * (<code>null</code> permitted).
759 * @param valueAxisLabel the label for the value axis (<code>null</code>
760 * permitted).
761 * @param dataset the dataset for the chart (<code>null</code> permitted).
762 * @param orientation the orientation (horizontal or vertical)
763 * (<code>null</code> not permitted).
764 * @param legend a flag specifying whether or not a legend is required.
765 * @param tooltips configure chart to generate tool tips?
766 * @param urls configure chart to generate URLs?
767 *
768 * @return A stacked bar chart with a 3D effect.
769 */
770 public static JFreeChart createStackedBarChart3D(String title,
771 String categoryAxisLabel,
772 String valueAxisLabel,
773 CategoryDataset dataset,
774 PlotOrientation orientation,
775 boolean legend,
776 boolean tooltips,
777 boolean urls) {
778
779 if (orientation == null) {
780 throw new IllegalArgumentException("Null 'orientation' argument.");
781 }
782 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
783 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);
784
785 // create the renderer...
786 CategoryItemRenderer renderer = new StackedBarRenderer3D();
787 if (tooltips) {
788 renderer.setBaseToolTipGenerator(
789 new StandardCategoryToolTipGenerator());
790 }
791 if (urls) {
792 renderer.setBaseItemURLGenerator(
793 new StandardCategoryURLGenerator());
794 }
795
796 // create the plot...
797 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
798 renderer);
799 plot.setOrientation(orientation);
800 if (orientation == PlotOrientation.HORIZONTAL) {
801 // change rendering order to ensure that bar overlapping is the
802 // right way around
803 plot.setColumnRenderingOrder(SortOrder.DESCENDING);
804 }
805
806 // create the chart...
807 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
808 plot, legend);
809
810 return chart;
811
812 }
813
814 /**
815 * Creates an area chart with default settings. The chart object returned
816 * by this method uses a {@link CategoryPlot} instance as the plot, with a
817 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
818 * range axis, and an {@link AreaRenderer} as the renderer.
819 *
820 * @param title the chart title (<code>null</code> permitted).
821 * @param categoryAxisLabel the label for the category axis
822 * (<code>null</code> permitted).
823 * @param valueAxisLabel the label for the value axis (<code>null</code>
824 * permitted).
825 * @param dataset the dataset for the chart (<code>null</code> permitted).
826 * @param orientation the plot orientation (<code>null</code> not
827 * permitted).
828 * @param legend a flag specifying whether or not a legend is required.
829 * @param tooltips configure chart to generate tool tips?
830 * @param urls configure chart to generate URLs?
831 *
832 * @return An area chart.
833 */
834 public static JFreeChart createAreaChart(String title,
835 String categoryAxisLabel,
836 String valueAxisLabel,
837 CategoryDataset dataset,
838 PlotOrientation orientation,
839 boolean legend,
840 boolean tooltips,
841 boolean urls) {
842
843 if (orientation == null) {
844 throw new IllegalArgumentException("Null 'orientation' argument.");
845 }
846 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
847 categoryAxis.setCategoryMargin(0.0);
848
849 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
850
851 AreaRenderer renderer = new AreaRenderer();
852 if (tooltips) {
853 renderer.setBaseToolTipGenerator(
854 new StandardCategoryToolTipGenerator());
855 }
856 if (urls) {
857 renderer.setBaseItemURLGenerator(
858 new StandardCategoryURLGenerator());
859 }
860
861 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
862 renderer);
863 plot.setOrientation(orientation);
864 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
865 plot, legend);
866
867 return chart;
868
869 }
870
871 /**
872 * Creates a stacked area chart with default settings. The chart object
873 * returned by this method uses a {@link CategoryPlot} instance as the
874 * plot, with a {@link CategoryAxis} for the domain axis, a
875 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer}
876 * as the renderer.
877 *
878 * @param title the chart title (<code>null</code> permitted).
879 * @param categoryAxisLabel the label for the category axis
880 * (<code>null</code> permitted).
881 * @param valueAxisLabel the label for the value axis (<code>null</code>
882 * permitted).
883 * @param dataset the dataset for the chart (<code>null</code> permitted).
884 * @param orientation the plot orientation (horizontal or vertical)
885 * (<code>null</code> not permitted).
886 * @param legend a flag specifying whether or not a legend is required.
887 * @param tooltips configure chart to generate tool tips?
888 * @param urls configure chart to generate URLs?
889 *
890 * @return A stacked area chart.
891 */
892 public static JFreeChart createStackedAreaChart(String title,
893 String categoryAxisLabel,
894 String valueAxisLabel,
895 CategoryDataset dataset,
896 PlotOrientation orientation,
897 boolean legend,
898 boolean tooltips,
899 boolean urls) {
900
901 if (orientation == null) {
902 throw new IllegalArgumentException("Null 'orientation' argument.");
903 }
904 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
905 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
906
907 StackedAreaRenderer renderer = new StackedAreaRenderer();
908 if (tooltips) {
909 renderer.setBaseToolTipGenerator(
910 new StandardCategoryToolTipGenerator());
911 }
912 if (urls) {
913 renderer.setBaseItemURLGenerator(
914 new StandardCategoryURLGenerator());
915 }
916
917 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
918 renderer);
919 plot.setOrientation(orientation);
920 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
921 plot, legend);
922
923 return chart;
924
925 }
926
927 /**
928 * Creates a line chart with default settings. The chart object returned
929 * by this method uses a {@link CategoryPlot} instance as the plot, with a
930 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
931 * range axis, and a {@link LineAndShapeRenderer} as the renderer.
932 *
933 * @param title the chart title (<code>null</code> permitted).
934 * @param categoryAxisLabel the label for the category axis
935 * (<code>null</code> permitted).
936 * @param valueAxisLabel the label for the value axis (<code>null</code>
937 * permitted).
938 * @param dataset the dataset for the chart (<code>null</code> permitted).
939 * @param orientation the chart orientation (horizontal or vertical)
940 * (<code>null</code> not permitted).
941 * @param legend a flag specifying whether or not a legend is required.
942 * @param tooltips configure chart to generate tool tips?
943 * @param urls configure chart to generate URLs?
944 *
945 * @return A line chart.
946 */
947 public static JFreeChart createLineChart(String title,
948 String categoryAxisLabel,
949 String valueAxisLabel,
950 CategoryDataset dataset,
951 PlotOrientation orientation,
952 boolean legend,
953 boolean tooltips,
954 boolean urls) {
955
956 if (orientation == null) {
957 throw new IllegalArgumentException("Null 'orientation' argument.");
958 }
959 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
960 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
961
962 LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
963 if (tooltips) {
964 renderer.setBaseToolTipGenerator(
965 new StandardCategoryToolTipGenerator());
966 }
967 if (urls) {
968 renderer.setBaseItemURLGenerator(
969 new StandardCategoryURLGenerator());
970 }
971 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
972 renderer);
973 plot.setOrientation(orientation);
974 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
975 plot, legend);
976
977 return chart;
978
979 }
980
981 /**
982 * Creates a line chart with default settings. The chart object returned by
983 * this method uses a {@link CategoryPlot} instance as the plot, with a
984 * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as
985 * the range axis, and a {@link LineRenderer3D} as the renderer.
986 *
987 * @param title the chart title (<code>null</code> permitted).
988 * @param categoryAxisLabel the label for the category axis
989 * (<code>null</code> permitted).
990 * @param valueAxisLabel the label for the value axis (<code>null</code>
991 * permitted).
992 * @param dataset the dataset for the chart (<code>null</code> permitted).
993 * @param orientation the chart orientation (horizontal or vertical)
994 * (<code>null</code> not permitted).
995 * @param legend a flag specifying whether or not a legend is required.
996 * @param tooltips configure chart to generate tool tips?
997 * @param urls configure chart to generate URLs?
998 *
999 * @return A line chart.
1000 */
1001 public static JFreeChart createLineChart3D(String title,
1002 String categoryAxisLabel,
1003 String valueAxisLabel,
1004 CategoryDataset dataset,
1005 PlotOrientation orientation,
1006 boolean legend,
1007 boolean tooltips,
1008 boolean urls) {
1009
1010 if (orientation == null) {
1011 throw new IllegalArgumentException("Null 'orientation' argument.");
1012 }
1013 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
1014 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);
1015
1016 LineRenderer3D renderer = new LineRenderer3D();
1017 if (tooltips) {
1018 renderer.setBaseToolTipGenerator(
1019 new StandardCategoryToolTipGenerator());
1020 }
1021 if (urls) {
1022 renderer.setBaseItemURLGenerator(
1023 new StandardCategoryURLGenerator());
1024 }
1025 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1026 renderer);
1027 plot.setOrientation(orientation);
1028 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1029 plot, legend);
1030
1031 return chart;
1032
1033 }
1034
1035 /**
1036 * Creates a Gantt chart using the supplied attributes plus default values
1037 * where required. The chart object returned by this method uses a
1038 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
1039 * for the domain axis, a {@link DateAxis} as the range axis, and a
1040 * {@link GanttRenderer} as the renderer.
1041 *
1042 * @param title the chart title (<code>null</code> permitted).
1043 * @param categoryAxisLabel the label for the category axis
1044 * (<code>null</code> permitted).
1045 * @param dateAxisLabel the label for the date axis
1046 * (<code>null</code> permitted).
1047 * @param dataset the dataset for the chart (<code>null</code> permitted).
1048 * @param legend a flag specifying whether or not a legend is required.
1049 * @param tooltips configure chart to generate tool tips?
1050 * @param urls configure chart to generate URLs?
1051 *
1052 * @return A Gantt chart.
1053 */
1054 public static JFreeChart createGanttChart(String title,
1055 String categoryAxisLabel,
1056 String dateAxisLabel,
1057 IntervalCategoryDataset dataset,
1058 boolean legend,
1059 boolean tooltips,
1060 boolean urls) {
1061
1062 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1063 DateAxis dateAxis = new DateAxis(dateAxisLabel);
1064
1065 CategoryItemRenderer renderer = new GanttRenderer();
1066 if (tooltips) {
1067 renderer.setBaseToolTipGenerator(
1068 new IntervalCategoryToolTipGenerator(
1069 "{3} - {4}", DateFormat.getDateInstance()));
1070 }
1071 if (urls) {
1072 renderer.setBaseItemURLGenerator(
1073 new StandardCategoryURLGenerator());
1074 }
1075
1076 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis,
1077 renderer);
1078 plot.setOrientation(PlotOrientation.HORIZONTAL);
1079 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1080 plot, legend);
1081
1082 return chart;
1083
1084 }
1085
1086 /**
1087 * Creates a waterfall chart. The chart object returned by this method
1088 * uses a {@link CategoryPlot} instance as the plot, with a
1089 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
1090 * range axis, and a {@link WaterfallBarRenderer} as the renderer.
1091 *
1092 * @param title the chart title (<code>null</code> permitted).
1093 * @param categoryAxisLabel the label for the category axis
1094 * (<code>null</code> permitted).
1095 * @param valueAxisLabel the label for the value axis (<code>null</code>
1096 * permitted).
1097 * @param dataset the dataset for the chart (<code>null</code> permitted).
1098 * @param orientation the plot orientation (horizontal or vertical)
1099 * (<code>null</code> NOT permitted).
1100 * @param legend a flag specifying whether or not a legend is required.
1101 * @param tooltips configure chart to generate tool tips?
1102 * @param urls configure chart to generate URLs?
1103 *
1104 * @return A waterfall chart.
1105 */
1106 public static JFreeChart createWaterfallChart(String title,
1107 String categoryAxisLabel,
1108 String valueAxisLabel,
1109 CategoryDataset dataset,
1110 PlotOrientation orientation,
1111 boolean legend,
1112 boolean tooltips,
1113 boolean urls) {
1114
1115 if (orientation == null) {
1116 throw new IllegalArgumentException("Null 'orientation' argument.");
1117 }
1118 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
1119 categoryAxis.setCategoryMargin(0.0);
1120
1121 ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
1122
1123 WaterfallBarRenderer renderer = new WaterfallBarRenderer();
1124 if (orientation == PlotOrientation.HORIZONTAL) {
1125 ItemLabelPosition position = new ItemLabelPosition(
1126 ItemLabelAnchor.CENTER, TextAnchor.CENTER,
1127 TextAnchor.CENTER, Math.PI / 2.0);
1128 renderer.setBasePositiveItemLabelPosition(position);
1129 renderer.setBaseNegativeItemLabelPosition(position);
1130 }
1131 else if (orientation == PlotOrientation.VERTICAL) {
1132 ItemLabelPosition position = new ItemLabelPosition(
1133 ItemLabelAnchor.CENTER, TextAnchor.CENTER,
1134 TextAnchor.CENTER, 0.0);
1135 renderer.setBasePositiveItemLabelPosition(position);
1136 renderer.setBaseNegativeItemLabelPosition(position);
1137 }
1138 if (tooltips) {
1139 StandardCategoryToolTipGenerator generator
1140 = new StandardCategoryToolTipGenerator();
1141 renderer.setBaseToolTipGenerator(generator);
1142 }
1143 if (urls) {
1144 renderer.setBaseItemURLGenerator(
1145 new StandardCategoryURLGenerator());
1146 }
1147
1148 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
1149 renderer);
1150 plot.clearRangeMarkers();
1151 Marker baseline = new ValueMarker(0.0);
1152 baseline.setPaint(Color.black);
1153 plot.addRangeMarker(baseline, Layer.FOREGROUND);
1154 plot.setOrientation(orientation);
1155 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1156 plot, legend);
1157
1158 return chart;
1159
1160 }
1161
1162 /**
1163 * Creates a polar plot for the specified dataset (x-values interpreted as
1164 * angles in degrees). The chart object returned by this method uses a
1165 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for
1166 * the radial axis.
1167 *
1168 * @param title the chart title (<code>null</code> permitted).
1169 * @param dataset the dataset (<code>null</code> permitted).
1170 * @param legend legend required?
1171 * @param tooltips tooltips required?
1172 * @param urls URLs required?
1173 *
1174 * @return A chart.
1175 */
1176 public static JFreeChart createPolarChart(String title,
1177 XYDataset dataset,
1178 boolean legend,
1179 boolean tooltips,
1180 boolean urls) {
1181
1182 PolarPlot plot = new PolarPlot();
1183 plot.setDataset(dataset);
1184 NumberAxis rangeAxis = new NumberAxis();
1185 rangeAxis.setAxisLineVisible(false);
1186 rangeAxis.setTickMarksVisible(false);
1187 rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
1188 plot.setAxis(rangeAxis);
1189 plot.setRenderer(new DefaultPolarItemRenderer());
1190 JFreeChart chart = new JFreeChart(
1191 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
1192 return chart;
1193
1194 }
1195
1196 /**
1197 * Creates a scatter plot with default settings. The chart object
1198 * returned by this method uses an {@link XYPlot} instance as the plot,
1199 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis}
1200 * as the range axis, and an {@link XYLineAndShapeRenderer} as the
1201 * renderer.
1202 *
1203 * @param title the chart title (<code>null</code> permitted).
1204 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
1205 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
1206 * @param dataset the dataset for the chart (<code>null</code> permitted).
1207 * @param orientation the plot orientation (horizontal or vertical)
1208 * (<code>null</code> NOT permitted).
1209 * @param legend a flag specifying whether or not a legend is required.
1210 * @param tooltips configure chart to generate tool tips?
1211 * @param urls configure chart to generate URLs?
1212 *
1213 * @return A scatter plot.
1214 */
1215 public static JFreeChart createScatterPlot(String title, String xAxisLabel,
1216 String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
1217 boolean legend, boolean tooltips, boolean urls) {
1218
1219 if (orientation == null) {
1220 throw new IllegalArgumentException("Null 'orientation' argument.");
1221 }
1222 NumberAxis xAxis = new NumberAxis(xAxisLabel);
1223 xAxis.setAutoRangeIncludesZero(false);
1224 NumberAxis yAxis = new NumberAxis(yAxisLabel);
1225 yAxis.setAutoRangeIncludesZero(false);
1226
1227 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
1228
1229 XYToolTipGenerator toolTipGenerator = null;
1230 if (tooltips) {
1231 toolTipGenerator = new StandardXYToolTipGenerator();
1232 }
1233
1234 XYURLGenerator urlGenerator = null;
1235 if (urls) {
1236 urlGenerator = new StandardXYURLGenerator();
1237 }
1238 XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
1239 renderer.setBaseToolTipGenerator(toolTipGenerator);
1240 renderer.setURLGenerator(urlGenerator);
1241 plot.setRenderer(renderer);
1242 plot.setOrientation(orientation);
1243
1244 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
1245 plot, legend);
1246 return chart;
1247
1248 }
1249
1250 /**
1251 * Creates and returns a default instance of an XY bar chart.
1252 * <P>
1253 * The chart object returned by this method uses an {@link XYPlot} instance
1254 * as the plot, with a {@link DateAxis} for the domain axis, a
1255 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the
1256 * renderer.
1257 *
1258 * @param title the chart title (<code>null</code> permitted).
1259 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
1260 * @param dateAxis make the domain axis display dates?
1261 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
1262 * @param dataset the dataset for the chart (<code>null</code> permitted).
1263 * @param orientation the orientation (hor