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.10 2007/01/17 16:26:29 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.setPositiveItemLabelPosition(position1); 598 ItemLabelPosition position2 = new ItemLabelPosition( 599 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); 600 renderer.setNegativeItemLabelPosition(position2); 601 } 602 else if (orientation == PlotOrientation.VERTICAL) { 603 ItemLabelPosition position1 = new ItemLabelPosition( 604 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); 605 renderer.setPositiveItemLabelPosition(position1); 606 ItemLabelPosition position2 = new ItemLabelPosition( 607 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); 608 renderer.setNegativeItemLabelPosition(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.setPositiveItemLabelPosition(position); 1129 renderer.setNegativeItemLabelPosition(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.setPositiveItemLabelPosition(position); 1136 renderer.setNegativeItemLabelPosition(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 (horizontal or vertical) 1264 * (<code>null</code> NOT permitted). 1265 * @param legend a flag specifying whether or not a legend is required. 1266 * @param tooltips configure chart to generate tool tips? 1267 * @param urls configure chart to generate URLs? 1268 * 1269 * @return An XY bar chart. 1270 */ 1271 public static JFreeChart createXYBarChart(String title, 1272 String xAxisLabel, 1273 boolean dateAxis, 1274 String yAxisLabel, 1275 IntervalXYDataset dataset, 1276 PlotOrientation orientation, 1277 boolean legend, 1278 boolean tooltips, 1279 boolean urls) { 1280 1281 if (orientation == null) { 1282 throw new IllegalArgumentException("Null 'orientation' argument."); 1283 } 1284 ValueAxis domainAxis = null; 1285 if (dateAxis) { 1286 domainAxis = new DateAxis(xAxisLabel); 1287 } 1288 else { 1289 NumberAxis axis = new NumberAxis(xAxisLabel); 1290 axis.setAutoRangeIncludesZero(false); 1291 domainAxis = axis; 1292 } 1293 ValueAxis valueAxis = new NumberAxis(yAxisLabel); 1294 1295 XYBarRenderer renderer = new XYBarRenderer(); 1296 if (tooltips) { 1297 XYToolTipGenerator tt; 1298 if (dateAxis) { 1299 tt = StandardXYToolTipGenerator.getTimeSeriesInstance(); 1300 } 1301 else { 1302 tt = new StandardXYToolTipGenerator(); 1303 } 1304 renderer.setBaseToolTipGenerator(tt); 1305 } 1306 if (urls) { 1307 renderer.setURLGenerator(new StandardXYURLGenerator()); 1308 } 1309 1310 XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer); 1311 plot.setOrientation(orientation); 1312 1313 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1314 plot, legend); 1315 1316 return chart; 1317 1318 } 1319 1320 /** 1321 * Creates an area chart using an {@link XYDataset}. 1322 * <P> 1323 * The chart object returned by this method uses an {@link XYPlot} instance 1324 * as the plot, with a {@link NumberAxis} for the domain axis, a 1325 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as 1326 * the renderer. 1327 * 1328 * @param title the chart title (<code>null</code> permitted). 1329 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1330 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1331 * @param dataset the dataset for the chart (<code>null</code> permitted). 1332 * @param orientation the plot orientation (horizontal or vertical) 1333 * (<code>null</code> NOT permitted). 1334 * @param legend a flag specifying whether or not a legend is required. 1335 * @param tooltips configure chart to generate tool tips? 1336 * @param urls configure chart to generate URLs? 1337 * 1338 * @return An XY area chart. 1339 */ 1340 public static JFreeChart createXYAreaChart(String title, 1341 String xAxisLabel, 1342 String yAxisLabel, 1343 XYDataset dataset, 1344 PlotOrientation orientation, 1345 boolean legend, 1346 boolean tooltips, 1347 boolean urls) { 1348 1349 if (orientation == null) { 1350 throw new IllegalArgumentException("Null 'orientation' argument."); 1351 } 1352 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1353 xAxis.setAutoRangeIncludesZero(false); 1354 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1355 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1356 plot.setOrientation(orientation); 1357 plot.setForegroundAlpha(0.5f); 1358 1359 XYToolTipGenerator tipGenerator = null; 1360 if (tooltips) { 1361 tipGenerator = new StandardXYToolTipGenerator(); 1362 } 1363 1364 XYURLGenerator urlGenerator = null; 1365 if (urls) { 1366 urlGenerator = new StandardXYURLGenerator(); 1367 } 1368 1369 plot.setRenderer( 1370 new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator) 1371 ); 1372 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1373 plot, legend); 1374 1375 return chart; 1376 1377 } 1378 1379 /** 1380 * Creates a stacked XY area plot. The chart object returned by this 1381 * method uses an {@link XYPlot} instance as the plot, with a 1382 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the 1383 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. 1384 * 1385 * @param title the chart title (<code>null</code> permitted). 1386 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1387 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1388 * @param dataset the dataset for the chart (<code>null</code> permitted). 1389 * @param orientation the plot orientation (horizontal or vertical) 1390 * (<code>null</code> NOT permitted). 1391 * @param legend a flag specifying whether or not a legend is required. 1392 * @param tooltips configure chart to generate tool tips? 1393 * @param urls configure chart to generate URLs? 1394 * 1395 * @return A stacked XY area chart. 1396 */ 1397 public static JFreeChart createStackedXYAreaChart(String title, 1398 String xAxisLabel, 1399 String yAxisLabel, 1400 TableXYDataset dataset, 1401 PlotOrientation orientation, 1402 boolean legend, 1403 boolean tooltips, 1404 boolean urls) { 1405 1406 if (orientation == null) { 1407 throw new IllegalArgumentException("Null 'orientation' argument."); 1408 } 1409 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1410 xAxis.setAutoRangeIncludesZero(false); 1411 xAxis.setLowerMargin(0.0); 1412 xAxis.setUpperMargin(0.0); 1413 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1414 XYToolTipGenerator toolTipGenerator = null; 1415 if (tooltips) { 1416 toolTipGenerator = new StandardXYToolTipGenerator(); 1417 } 1418 1419 XYURLGenerator urlGenerator = null; 1420 if (urls) { 1421 urlGenerator = new StandardXYURLGenerator(); 1422 } 1423 StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2( 1424 toolTipGenerator, urlGenerator); 1425 renderer.setOutline(true); 1426 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1427 plot.setOrientation(orientation); 1428 1429 plot.setRangeAxis(yAxis); // forces recalculation of the axis range 1430 1431 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1432 plot, legend); 1433 return chart; 1434 1435 } 1436 1437 /** 1438 * Creates a line chart (based on an {@link XYDataset}) with default 1439 * settings. 1440 * 1441 * @param title the chart title (<code>null</code> permitted). 1442 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1443 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1444 * @param dataset the dataset for the chart (<code>null</code> permitted). 1445 * @param orientation the plot orientation (horizontal or vertical) 1446 * (<code>null</code> NOT permitted). 1447 * @param legend a flag specifying whether or not a legend is required. 1448 * @param tooltips configure chart to generate tool tips? 1449 * @param urls configure chart to generate URLs? 1450 * 1451 * @return The chart. 1452 */ 1453 public static JFreeChart createXYLineChart(String title, 1454 String xAxisLabel, 1455 String yAxisLabel, 1456 XYDataset dataset, 1457 PlotOrientation orientation, 1458 boolean legend, 1459 boolean tooltips, 1460 boolean urls) { 1461 1462 if (orientation == null) { 1463 throw new IllegalArgumentException("Null 'orientation' argument."); 1464 } 1465 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1466 xAxis.setAutoRangeIncludesZero(false); 1467 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1468 XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); 1469 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1470 plot.setOrientation(orientation); 1471 if (tooltips) { 1472 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1473 } 1474 if (urls) { 1475 renderer.setURLGenerator(new StandardXYURLGenerator()); 1476 } 1477 1478 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1479 plot, legend); 1480 1481 return chart; 1482 1483 } 1484 1485 /** 1486 * Creates a stepped XY plot with default settings. 1487 * 1488 * @param title the chart title (<code>null</code> permitted). 1489 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1490 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1491 * @param dataset the dataset for the chart (<code>null</code> permitted). 1492 * @param orientation the plot orientation (horizontal or vertical) 1493 * (<code>null</code> NOT permitted). 1494 * @param legend a flag specifying whether or not a legend is required. 1495 * @param tooltips configure chart to generate tool tips? 1496 * @param urls configure chart to generate URLs? 1497 * 1498 * @return A chart. 1499 */ 1500 public static JFreeChart createXYStepChart(String title, 1501 String xAxisLabel, 1502 String yAxisLabel, 1503 XYDataset dataset, 1504 PlotOrientation orientation, 1505 boolean legend, 1506 boolean tooltips, 1507 boolean urls) { 1508 1509 if (orientation == null) { 1510 throw new IllegalArgumentException("Null 'orientation' argument."); 1511 } 1512 DateAxis xAxis = new DateAxis(xAxisLabel); 1513 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1514 yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 1515 1516 XYToolTipGenerator toolTipGenerator = null; 1517 if (tooltips) { 1518 toolTipGenerator = new StandardXYToolTipGenerator(); 1519 } 1520 1521 XYURLGenerator urlGenerator = null; 1522 if (urls) { 1523 urlGenerator = new StandardXYURLGenerator(); 1524 } 1525 XYItemRenderer renderer 1526 = new XYStepRenderer(toolTipGenerator, urlGenerator); 1527 1528 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1529 plot.setRenderer(renderer); 1530 plot.setOrientation(orientation); 1531 plot.setDomainCrosshairVisible(false); 1532 plot.setRangeCrosshairVisible(false); 1533 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1534 plot, legend); 1535 return chart; 1536 1537 } 1538 1539 /** 1540 * Creates a filled stepped XY plot with default settings. 1541 * 1542 * @param title the chart title (<code>null</code> permitted). 1543 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1544 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1545 * @param dataset the dataset for the chart (<code>null</code> permitted). 1546 * @param orientation the plot orientation (horizontal or vertical) 1547 * (<code>null</code> NOT permitted). 1548 * @param legend a flag specifying whether or not a legend is required. 1549 * @param tooltips configure chart to generate tool tips? 1550 * @param urls configure chart to generate URLs? 1551 * 1552 * @return A chart. 1553 */ 1554 public static JFreeChart createXYStepAreaChart(String title, 1555 String xAxisLabel, 1556 String yAxisLabel, 1557 XYDataset dataset, 1558 PlotOrientation orientation, 1559 boolean legend, 1560 boolean tooltips, 1561 boolean urls) { 1562 1563 if (orientation == null) { 1564 throw new IllegalArgumentException("Null 'orientation' argument."); 1565 } 1566 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1567 xAxis.setAutoRangeIncludesZero(false); 1568 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1569 1570 XYToolTipGenerator toolTipGenerator = null; 1571 if (tooltips) { 1572 toolTipGenerator = new StandardXYToolTipGenerator(); 1573 } 1574 1575 XYURLGenerator urlGenerator = null; 1576 if (urls) { 1577 urlGenerator = new StandardXYURLGenerator(); 1578 } 1579 XYItemRenderer renderer = new XYStepAreaRenderer( 1580 XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, 1581 urlGenerator); 1582 1583 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1584 plot.setRenderer(renderer); 1585 plot.setOrientation(orientation); 1586 plot.setDomainCrosshairVisible(false); 1587 plot.setRangeCrosshairVisible(false); 1588 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1589 plot, legend); 1590 return chart; 1591 } 1592 1593 /** 1594 * Creates and returns a time series chart. A time series chart is an 1595 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a 1596 * {@link NumberAxis} for the y-axis. The default renderer is an 1597 * {@link XYLineAndShapeRenderer}. 1598 * <P> 1599 * A convenient dataset to use with this chart is a 1600 * {@link org.jfree.data.time.TimeSeriesCollection}. 1601 * 1602 * @param title the chart title (<code>null</code> permitted). 1603 * @param timeAxisLabel a label for the time axis (<code>null</code> 1604 * permitted). 1605 * @param valueAxisLabel a label for the value axis (<code>null</code> 1606 * permitted). 1607 * @param dataset the dataset for the chart (<code>null</code> permitted). 1608 * @param legend a flag specifying whether or not a legend is required. 1609 * @param tooltips configure chart to generate tool tips? 1610 * @param urls configure chart to generate URLs? 1611 * 1612 * @return A time series chart. 1613 */ 1614 public static JFreeChart createTimeSeriesChart(String title, 1615 String timeAxisLabel, 1616 String valueAxisLabel, 1617 XYDataset dataset, 1618 boolean legend, 1619 boolean tooltips, 1620 boolean urls) { 1621 1622 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1623 timeAxis.setLowerMargin(0.02); // reduce the default margins 1624 timeAxis.setUpperMargin(0.02); 1625 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1626 valueAxis.setAutoRangeIncludesZero(false); // override default 1627 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1628 1629 XYToolTipGenerator toolTipGenerator = null; 1630 if (tooltips) { 1631 toolTipGenerator 1632 = StandardXYToolTipGenerator.getTimeSeriesInstance(); 1633 } 1634 1635 XYURLGenerator urlGenerator = null; 1636 if (urls) { 1637 urlGenerator = new StandardXYURLGenerator(); 1638 } 1639 1640 XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, 1641 false); 1642 renderer.setBaseToolTipGenerator(toolTipGenerator); 1643 renderer.setURLGenerator(urlGenerator); 1644 plot.setRenderer(renderer); 1645 1646 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1647 plot, legend); 1648 return chart; 1649 1650 } 1651 1652 /** 1653 * Creates and returns a default instance of a candlesticks chart. 1654 * 1655 * @param title the chart title (<code>null</code> permitted). 1656 * @param timeAxisLabel a label for the time axis (<code>null</code> 1657 * permitted). 1658 * @param valueAxisLabel a label for the value axis (<code>null</code> 1659 * permitted). 1660 * @param dataset the dataset for the chart (<code>null</code> permitted). 1661 * @param legend a flag specifying whether or not a legend is required. 1662 * 1663 * @return A candlestick chart. 1664 */ 1665 public static JFreeChart createCandlestickChart(String title, 1666 String timeAxisLabel, 1667 String valueAxisLabel, 1668 OHLCDataset dataset, 1669 boolean legend) { 1670 1671 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1672 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1673 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1674 plot.setRenderer(new CandlestickRenderer()); 1675 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1676 plot, legend); 1677 return chart; 1678 1679 } 1680 1681 /** 1682 * Creates and returns a default instance of a high-low-open-close chart. 1683 * 1684 * @param title the chart title (<code>null</code> permitted). 1685 * @param timeAxisLabel a label for the time axis (<code>null</code> 1686 * permitted). 1687 * @param valueAxisLabel a label for the value axis (<code>null</code> 1688 * permitted). 1689 * @param dataset the dataset for the chart (<code>null</code> permitted). 1690 * @param legend a flag specifying whether or not a legend is required. 1691 * 1692 * @return A high-low-open-close chart. 1693 */ 1694 public static JFreeChart createHighLowChart(String title, 1695 String timeAxisLabel, 1696 String valueAxisLabel, 1697 OHLCDataset dataset, 1698 boolean legend) { 1699 1700 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1701 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1702 HighLowRenderer renderer = new HighLowRenderer(); 1703 renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); 1704 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1705 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1706 plot, legend); 1707 return chart; 1708 1709 } 1710 1711 /** 1712 * Creates and returns a default instance of a high-low-open-close chart 1713 * with a special timeline. This timeline can be a 1714 * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday 1715 * through Friday timeline that will remove Saturdays and Sundays from 1716 * the axis. 1717 * 1718 * @param title the chart title (<code>null</code> permitted). 1719 * @param timeAxisLabel a label for the time axis (<code>null</code> 1720 * permitted). 1721 * @param valueAxisLabel a label for the value axis (<code>null</code> 1722 * permitted). 1723 * @param dataset the dataset for the chart (<code>null</code> permitted). 1724 * @param timeline the timeline. 1725 * @param legend a flag specifying whether or not a legend is required. 1726 * 1727 * @return A high-low-open-close chart. 1728 */ 1729 public static JFreeChart createHighLowChart(String title, 1730 String timeAxisLabel, 1731 String valueAxisLabel, 1732 OHLCDataset dataset, 1733 Timeline timeline, 1734 boolean legend) { 1735 1736 DateAxis timeAxis = new DateAxis(timeAxisLabel); 1737 timeAxis.setTimeline(timeline); 1738 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1739 HighLowRenderer renderer = new HighLowRenderer(); 1740 renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); 1741 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1742 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1743 plot, legend); 1744 return chart; 1745 1746 } 1747 1748 /** 1749 * Creates a bubble chart with default settings. The chart is composed of 1750 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, 1751 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} 1752 * to draw the data items. 1753 * 1754 * @param title the chart title (<code>null</code> permitted). 1755 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1756 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1757 * @param dataset the dataset for the chart (<code>null</code> permitted). 1758 * @param orientation the orientation (horizontal or vertical) 1759 * (<code>null</code> NOT permitted). 1760 * @param legend a flag specifying whether or not a legend is required. 1761 * @param tooltips configure chart to generate tool tips? 1762 * @param urls configure chart to generate URLs? 1763 * 1764 * @return A bubble chart. 1765 */ 1766 public static JFreeChart createBubbleChart(String title, 1767 String xAxisLabel, 1768 String yAxisLabel, 1769 XYZDataset dataset, 1770 PlotOrientation orientation, 1771 boolean legend, 1772 boolean tooltips, 1773 boolean urls) { 1774 1775 if (orientation == null) { 1776 throw new IllegalArgumentException("Null 'orientation' argument."); 1777 } 1778 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1779 xAxis.setAutoRangeIncludesZero(false); 1780 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1781 yAxis.setAutoRangeIncludesZero(false); 1782 1783 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1784 1785 XYItemRenderer renderer = new XYBubbleRenderer( 1786 XYBubbleRenderer.SCALE_ON_RANGE_AXIS); 1787 if (tooltips) { 1788 renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); 1789 } 1790 if (urls) { 1791 renderer.setURLGenerator(new StandardXYZURLGenerator()); 1792 } 1793 plot.setRenderer(renderer); 1794 plot.setOrientation(orientation); 1795 1796 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1797 plot, legend); 1798 1799 return chart; 1800 1801 } 1802 1803 /** 1804 * Creates a histogram chart. This chart is constructed with an 1805 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range 1806 * axes are {@link NumberAxis} instances. 1807 * 1808 * @param title the chart title (<code>null</code> permitted). 1809 * @param xAxisLabel the x axis label (<code>null</code> permitted). 1810 * @param yAxisLabel the y axis label (<code>null</code> permitted). 1811 * @param dataset the dataset (<code>null</code> permitted). 1812 * @param orientation the orientation (horizontal or vertical) 1813 * (<code>null</code> NOT permitted). 1814 * @param legend create a legend? 1815 * @param tooltips display tooltips? 1816 * @param urls generate URLs? 1817 * 1818 * @return The chart. 1819 */ 1820 public static JFreeChart createHistogram(String title, 1821 String xAxisLabel, 1822 String yAxisLabel, 1823 IntervalXYDataset dataset, 1824 PlotOrientation orientation, 1825 boolean legend, 1826 boolean tooltips, 1827 boolean urls) { 1828 1829 if (orientation == null) { 1830 throw new IllegalArgumentException("Null 'orientation' argument."); 1831 } 1832 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1833 xAxis.setAutoRangeIncludesZero(false); 1834 ValueAxis yAxis = new NumberAxis(yAxisLabel); 1835 1836 XYItemRenderer renderer = new XYBarRenderer(); 1837 if (tooltips) { 1838 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1839 } 1840 if (urls) { 1841 renderer.setURLGenerator(new StandardXYURLGenerator()); 1842 } 1843 1844 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1845 plot.setOrientation(orientation); 1846 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1847 plot, legend); 1848 return chart; 1849 1850 } 1851 1852 /** 1853 * Creates and returns a default instance of a box and whisker chart 1854 * based on data from a {@link BoxAndWhiskerCategoryDataset}. 1855 * 1856 * @param title the chart title (<code>null</code> permitted). 1857 * @param categoryAxisLabel a label for the category axis 1858 * (<code>null</code> permitted). 1859 * @param valueAxisLabel a label for the value axis (<code>null</code> 1860 * permitted). 1861 * @param dataset the dataset for the chart (<code>null</code> permitted). 1862 * @param legend a flag specifying whether or not a legend is required. 1863 * 1864 * @return A box and whisker chart. 1865 * 1866 * @since 1.0.4 1867 */ 1868 public static JFreeChart createBoxAndWhiskerChart(String title, 1869 String categoryAxisLabel, String valueAxisLabel, 1870 BoxAndWhiskerCategoryDataset dataset, boolean legend) { 1871 1872 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1873 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1874 valueAxis.setAutoRangeIncludesZero(false); 1875 1876 BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); 1877 renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); 1878 1879 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 1880 renderer); 1881 return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 1882 legend); 1883 } 1884 1885 /** 1886 * Creates and returns a default instance of a box and whisker chart. 1887 * 1888 * @param title the chart title (<code>null</code> permitted). 1889 * @param timeAxisLabel a label for the time axis (<code>null</code> 1890 * permitted). 1891 * @param valueAxisLabel a label for the value axis (<code>null</code> 1892 * permitted). 1893 * @param dataset the dataset for the chart (<code>null</code> permitted). 1894 * @param legend a flag specifying whether or not a legend is required. 1895 * 1896 * @return A box and whisker chart. 1897 */ 1898 public static JFreeChart createBoxAndWhiskerChart(String title, 1899 String timeAxisLabel, 1900 String valueAxisLabel, 1901 BoxAndWhiskerXYDataset dataset, 1902 boolean legend) { 1903 1904 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1905 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1906 valueAxis.setAutoRangeIncludesZero(false); 1907 XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0); 1908 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1909 return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 1910 legend); 1911 1912 } 1913 1914 /** 1915 * Creates a wind plot with default settings. 1916 * 1917 * @param title the chart title (<code>null</code> permitted). 1918 * @param xAxisLabel a label for the x-axis (<code>null</code> permitted). 1919 * @param yAxisLabel a label for the y-axis (<code>null</code> permitted). 1920 * @param dataset the dataset for the chart (<code>null</code> permitted). 1921 * @param legend a flag that controls whether or not a legend is created. 1922 * @param tooltips configure chart to generate tool tips? 1923 * @param urls configure chart to generate URLs? 1924 * 1925 * @return A wind plot. 1926 * 1927 */ 1928 public static JFreeChart createWindPlot(String title, 1929 String xAxisLabel, 1930 String yAxisLabel, 1931 WindDataset dataset, 1932 boolean legend, 1933 boolean tooltips, 1934 boolean urls) { 1935 1936 ValueAxis xAxis = new DateAxis(xAxisLabel); 1937 ValueAxis yAxis = new NumberAxis(yAxisLabel); 1938 yAxis.setRange(-12.0, 12.0); 1939 1940 WindItemRenderer renderer = new WindItemRenderer(); 1941 if (tooltips) { 1942 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1943 } 1944 if (urls) { 1945 renderer.setURLGenerator(new StandardXYURLGenerator()); 1946 } 1947 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1948 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1949 plot, legend); 1950 1951 return chart; 1952 1953 } 1954 1955 /** 1956 * Creates a wafer map chart. 1957 * 1958 * @param title the chart title (<code>null</code> permitted). 1959 * @param dataset the dataset (<code>null</code> permitted). 1960 * @param orientation the plot orientation (horizontal or vertical) 1961 * (<code>null</code> NOT permitted. 1962 * @param legend display a legend? 1963 * @param tooltips generate tooltips? 1964 * @param urls generate URLs? 1965 * 1966 * @return A wafer map chart. 1967 */ 1968 public static JFreeChart createWaferMapChart(String title, 1969 WaferMapDataset dataset, 1970 PlotOrientation orientation, 1971 boolean legend, 1972 boolean tooltips, 1973 boolean urls) { 1974 1975 if (orientation == null) { 1976 throw new IllegalArgumentException("Null 'orientation' argument."); 1977 } 1978 WaferMapPlot plot = new WaferMapPlot(dataset); 1979 WaferMapRenderer renderer = new WaferMapRenderer(); 1980 plot.setRenderer(renderer); 1981 1982 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1983 plot, legend); 1984 1985 return chart; 1986 } 1987 1988 }