001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2006, 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-2006, 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.6 2006/01/26 11:49:44 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.0 --------------------------------------------- 109 * 26-Jan-2006 : Corrected API docs for createScatterPlot() (DG); 110 * 111 */ 112 113 package org.jfree.chart; 114 115 import java.awt.Color; 116 import java.awt.Font; 117 import java.text.DateFormat; 118 import java.text.NumberFormat; 119 import java.util.Iterator; 120 import java.util.List; 121 122 import org.jfree.chart.axis.CategoryAxis; 123 import org.jfree.chart.axis.CategoryAxis3D; 124 import org.jfree.chart.axis.DateAxis; 125 import org.jfree.chart.axis.NumberAxis; 126 import org.jfree.chart.axis.NumberAxis3D; 127 import org.jfree.chart.axis.Timeline; 128 import org.jfree.chart.axis.ValueAxis; 129 import org.jfree.chart.labels.HighLowItemLabelGenerator; 130 import org.jfree.chart.labels.IntervalCategoryToolTipGenerator; 131 import org.jfree.chart.labels.ItemLabelAnchor; 132 import org.jfree.chart.labels.ItemLabelPosition; 133 import org.jfree.chart.labels.PieToolTipGenerator; 134 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 135 import org.jfree.chart.labels.StandardPieSectionLabelGenerator; 136 import org.jfree.chart.labels.StandardPieToolTipGenerator; 137 import org.jfree.chart.labels.StandardXYToolTipGenerator; 138 import org.jfree.chart.labels.StandardXYZToolTipGenerator; 139 import org.jfree.chart.labels.XYToolTipGenerator; 140 import org.jfree.chart.plot.CategoryPlot; 141 import org.jfree.chart.plot.Marker; 142 import org.jfree.chart.plot.MultiplePiePlot; 143 import org.jfree.chart.plot.PiePlot; 144 import org.jfree.chart.plot.PiePlot3D; 145 import org.jfree.chart.plot.PlotOrientation; 146 import org.jfree.chart.plot.PolarPlot; 147 import org.jfree.chart.plot.RingPlot; 148 import org.jfree.chart.plot.ValueMarker; 149 import org.jfree.chart.plot.WaferMapPlot; 150 import org.jfree.chart.plot.XYPlot; 151 import org.jfree.chart.renderer.DefaultPolarItemRenderer; 152 import org.jfree.chart.renderer.WaferMapRenderer; 153 import org.jfree.chart.renderer.category.AreaRenderer; 154 import org.jfree.chart.renderer.category.BarRenderer; 155 import org.jfree.chart.renderer.category.BarRenderer3D; 156 import org.jfree.chart.renderer.category.CategoryItemRenderer; 157 import org.jfree.chart.renderer.category.GanttRenderer; 158 import org.jfree.chart.renderer.category.LineAndShapeRenderer; 159 import org.jfree.chart.renderer.category.LineRenderer3D; 160 import org.jfree.chart.renderer.category.StackedAreaRenderer; 161 import org.jfree.chart.renderer.category.StackedBarRenderer; 162 import org.jfree.chart.renderer.category.StackedBarRenderer3D; 163 import org.jfree.chart.renderer.category.WaterfallBarRenderer; 164 import org.jfree.chart.renderer.xy.CandlestickRenderer; 165 import org.jfree.chart.renderer.xy.HighLowRenderer; 166 import org.jfree.chart.renderer.xy.StackedXYAreaRenderer; 167 import org.jfree.chart.renderer.xy.WindItemRenderer; 168 import org.jfree.chart.renderer.xy.XYAreaRenderer; 169 import org.jfree.chart.renderer.xy.XYBarRenderer; 170 import org.jfree.chart.renderer.xy.XYBoxAndWhiskerRenderer; 171 import org.jfree.chart.renderer.xy.XYBubbleRenderer; 172 import org.jfree.chart.renderer.xy.XYItemRenderer; 173 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 174 import org.jfree.chart.renderer.xy.XYStepAreaRenderer; 175 import org.jfree.chart.renderer.xy.XYStepRenderer; 176 import org.jfree.chart.title.TextTitle; 177 import org.jfree.chart.urls.PieURLGenerator; 178 import org.jfree.chart.urls.StandardCategoryURLGenerator; 179 import org.jfree.chart.urls.StandardPieURLGenerator; 180 import org.jfree.chart.urls.StandardXYURLGenerator; 181 import org.jfree.chart.urls.StandardXYZURLGenerator; 182 import org.jfree.chart.urls.XYURLGenerator; 183 import org.jfree.data.category.CategoryDataset; 184 import org.jfree.data.category.IntervalCategoryDataset; 185 import org.jfree.data.general.DefaultPieDataset; 186 import org.jfree.data.general.PieDataset; 187 import org.jfree.data.general.WaferMapDataset; 188 import org.jfree.data.statistics.BoxAndWhiskerXYDataset; 189 import org.jfree.data.xy.IntervalXYDataset; 190 import org.jfree.data.xy.OHLCDataset; 191 import org.jfree.data.xy.TableXYDataset; 192 import org.jfree.data.xy.WindDataset; 193 import org.jfree.data.xy.XYDataset; 194 import org.jfree.data.xy.XYZDataset; 195 import org.jfree.ui.Layer; 196 import org.jfree.ui.RectangleEdge; 197 import org.jfree.ui.RectangleInsets; 198 import org.jfree.ui.TextAnchor; 199 import org.jfree.util.SortOrder; 200 import org.jfree.util.TableOrder; 201 202 /** 203 * A collection of utility methods for creating some standard charts with 204 * JFreeChart. 205 */ 206 public abstract class ChartFactory { 207 208 /** 209 * Creates a pie chart with default settings. 210 * <P> 211 * The chart object returned by this method uses a {@link PiePlot} instance 212 * as the plot. 213 * 214 * @param title the chart title (<code>null</code> permitted). 215 * @param dataset the dataset for the chart (<code>null</code> permitted). 216 * @param legend a flag specifying whether or not a legend is required. 217 * @param tooltips configure chart to generate tool tips? 218 * @param urls configure chart to generate URLs? 219 * 220 * @return A pie chart. 221 */ 222 public static JFreeChart createPieChart(String title, 223 PieDataset dataset, 224 boolean legend, 225 boolean tooltips, 226 boolean urls) { 227 228 PiePlot plot = new PiePlot(dataset); 229 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 230 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 231 if (tooltips) { 232 plot.setToolTipGenerator( 233 new StandardPieToolTipGenerator( 234 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT 235 ) 236 ); 237 } 238 if (urls) { 239 plot.setURLGenerator(new StandardPieURLGenerator()); 240 } 241 return new JFreeChart( 242 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 243 ); 244 245 } 246 247 /** 248 * Creates a pie chart with default settings that compares 2 datasets. 249 * The colour of each section will be determined by the move from the value 250 * for the same key in <code>previousDataset</code>. ie if value1 > value2 251 * then the section will be in green (unless <code>greenForIncrease</code> 252 * is <code>false</code>, in which case it would be <code>red</code>). 253 * Each section can have a shade of red or green as the difference can be 254 * tailored between 0% (black) and percentDiffForMaxScale% (bright 255 * red/green). 256 * <p> 257 * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a 258 * difference of 5% will have a half shade of red/green, a difference of 259 * 10% or more will have a maximum shade/brightness of red/green. 260 * <P> 261 * The chart object returned by this method uses a {@link PiePlot} instance 262 * as the plot. 263 * <p> 264 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit 265 * Xhenseval</a>. 266 * 267 * @param title the chart title (<code>null</code> permitted). 268 * @param dataset the dataset for the chart (<code>null</code> permitted). 269 * @param previousDataset the dataset for the last run, this will be used 270 * to compare each key in the dataset 271 * @param percentDiffForMaxScale scale goes from bright red/green to black, 272 * percentDiffForMaxScale indicate the change 273 * required to reach top scale. 274 * @param greenForIncrease an increase since previousDataset will be 275 * displayed in green (decrease red) if true. 276 * @param legend a flag specifying whether or not a legend is required. 277 * @param tooltips configure chart to generate tool tips? 278 * @param urls configure chart to generate URLs? 279 * @param subTitle displays a subtitle with colour scheme if true 280 * @param showDifference create a new dataset that will show the % 281 * difference between the two datasets. 282 * 283 * @return A pie chart. 284 */ 285 public static JFreeChart createPieChart(String title, 286 PieDataset dataset, 287 PieDataset previousDataset, 288 int percentDiffForMaxScale, 289 boolean greenForIncrease, 290 boolean legend, 291 boolean tooltips, 292 boolean urls, 293 boolean subTitle, 294 boolean showDifference) { 295 296 PiePlot plot = new PiePlot(dataset); 297 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 298 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 299 300 if (tooltips) { 301 plot.setToolTipGenerator( 302 new StandardPieToolTipGenerator( 303 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT 304 ) 305 ); 306 } 307 if (urls) { 308 plot.setURLGenerator(new StandardPieURLGenerator()); 309 } 310 311 List keys = dataset.getKeys(); 312 DefaultPieDataset series = null; 313 if (showDifference) { 314 series = new DefaultPieDataset(); 315 } 316 317 double colorPerPercent = 255.0 / percentDiffForMaxScale; 318 for (Iterator it = keys.iterator(); it.hasNext();) { 319 Comparable key = (Comparable) it.next(); 320 Number newValue = dataset.getValue(key); 321 Number oldValue = previousDataset.getValue(key); 322 int section = dataset.getIndex(key); 323 324 if (oldValue == null) { 325 if (greenForIncrease) { 326 plot.setSectionPaint(section, Color.green); 327 } 328 else { 329 plot.setSectionPaint(section, Color.red); 330 } 331 if (showDifference) { 332 series.setValue(key + " (+100%)", newValue); 333 } 334 } 335 else { 336 double percentChange = (newValue.doubleValue() 337 / oldValue.doubleValue() - 1.0) * 100.0; 338 double shade 339 = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 340 : Math.abs(percentChange) * colorPerPercent); 341 if (greenForIncrease 342 && newValue.doubleValue() > oldValue.doubleValue() 343 || !greenForIncrease && newValue.doubleValue() 344 < oldValue.doubleValue()) { 345 plot.setSectionPaint(section, new Color(0, (int) shade, 0)); 346 } 347 else { 348 plot.setSectionPaint(section, new Color((int) shade, 0, 0)); 349 } 350 if (showDifference) { 351 series.setValue( 352 key + " (" + (percentChange >= 0 ? "+" : "") 353 + NumberFormat.getPercentInstance().format( 354 percentChange / 100.0) + ")", newValue 355 ); 356 } 357 } 358 } 359 360 if (showDifference) { 361 plot.setDataset(series); 362 } 363 364 JFreeChart chart = new JFreeChart( 365 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 366 ); 367 368 if (subTitle) { 369 TextTitle subtitle = null; 370 subtitle = new TextTitle( 371 "Bright " + (greenForIncrease ? "red" : "green") 372 + "=change >=-" + percentDiffForMaxScale + "%, Bright " 373 + (!greenForIncrease ? "red" : "green") + "=change >=+" 374 + percentDiffForMaxScale + "%", 375 new Font("SansSerif", Font.PLAIN, 10) 376 ); 377 chart.addSubtitle(subtitle); 378 } 379 380 return chart; 381 } 382 383 /** 384 * Creates a ring chart with default settings. 385 * <P> 386 * The chart object returned by this method uses a {@link RingPlot} 387 * instance as the plot. 388 * 389 * @param title the chart title (<code>null</code> permitted). 390 * @param dataset the dataset for the chart (<code>null</code> permitted). 391 * @param legend a flag specifying whether or not a legend is required. 392 * @param tooltips configure chart to generate tool tips? 393 * @param urls configure chart to generate URLs? 394 * 395 * @return A pie chart. 396 */ 397 public static JFreeChart createRingChart(String title, 398 PieDataset dataset, 399 boolean legend, 400 boolean tooltips, 401 boolean urls) { 402 403 RingPlot plot = new RingPlot(dataset); 404 plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); 405 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 406 if (tooltips) { 407 plot.setToolTipGenerator( 408 new StandardPieToolTipGenerator( 409 StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT 410 ) 411 ); 412 } 413 if (urls) { 414 plot.setURLGenerator(new StandardPieURLGenerator()); 415 } 416 return new JFreeChart( 417 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 418 ); 419 420 } 421 422 /** 423 * Creates a chart that displays multiple pie plots. The chart object 424 * returned by this method uses a {@link MultiplePiePlot} instance as the 425 * plot. 426 * 427 * @param title the chart title (<code>null</code> permitted). 428 * @param dataset the dataset (<code>null</code> permitted). 429 * @param order the order that the data is extracted (by row or by column) 430 * (<code>null</code> not permitted). 431 * @param legend include a legend? 432 * @param tooltips generate tooltips? 433 * @param urls generate URLs? 434 * 435 * @return A chart. 436 */ 437 public static JFreeChart createMultiplePieChart(String title, 438 CategoryDataset dataset, 439 TableOrder order, 440 boolean legend, 441 boolean tooltips, 442 boolean urls) { 443 444 if (order == null) { 445 throw new IllegalArgumentException("Null 'order' argument."); 446 } 447 MultiplePiePlot plot = new MultiplePiePlot(dataset); 448 plot.setDataExtractOrder(order); 449 plot.setBackgroundPaint(null); 450 plot.setOutlineStroke(null); 451 452 if (tooltips) { 453 PieToolTipGenerator tooltipGenerator 454 = new StandardPieToolTipGenerator(); 455 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 456 pp.setToolTipGenerator(tooltipGenerator); 457 } 458 459 if (urls) { 460 PieURLGenerator urlGenerator = new StandardPieURLGenerator(); 461 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 462 pp.setURLGenerator(urlGenerator); 463 } 464 465 JFreeChart chart = new JFreeChart( 466 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 467 ); 468 469 return chart; 470 471 } 472 473 /** 474 * Creates a 3D pie chart using the specified dataset. The chart object 475 * returned by this method uses a {@link PiePlot3D} instance as the 476 * plot. 477 * 478 * @param title the chart title (<code>null</code> permitted). 479 * @param dataset the dataset for the chart (<code>null</code> permitted). 480 * @param legend a flag specifying whether or not a legend is required. 481 * @param tooltips configure chart to generate tool tips? 482 * @param urls configure chart to generate URLs? 483 * 484 * @return A pie chart. 485 */ 486 public static JFreeChart createPieChart3D(String title, 487 PieDataset dataset, 488 boolean legend, 489 boolean tooltips, 490 boolean urls) { 491 492 PiePlot3D plot = new PiePlot3D(dataset); 493 plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); 494 if (tooltips) { 495 plot.setToolTipGenerator(new StandardPieToolTipGenerator()); 496 } 497 if (urls) { 498 plot.setURLGenerator(new StandardPieURLGenerator()); 499 } 500 return new JFreeChart( 501 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 502 ); 503 504 } 505 506 /** 507 * Creates a chart that displays multiple pie plots. The chart object 508 * returned by this method uses a {@link MultiplePiePlot} instance as the 509 * plot. 510 * 511 * @param title the chart title (<code>null</code> permitted). 512 * @param dataset the dataset (<code>null</code> permitted). 513 * @param order the order that the data is extracted (by row or by column) 514 * (<code>null</code> not permitted). 515 * @param legend include a legend? 516 * @param tooltips generate tooltips? 517 * @param urls generate URLs? 518 * 519 * @return A chart. 520 */ 521 public static JFreeChart createMultiplePieChart3D(String title, 522 CategoryDataset dataset, 523 TableOrder order, 524 boolean legend, 525 boolean tooltips, 526 boolean urls) { 527 528 if (order == null) { 529 throw new IllegalArgumentException("Null 'order' argument."); 530 } 531 MultiplePiePlot plot = new MultiplePiePlot(dataset); 532 plot.setDataExtractOrder(order); 533 plot.setBackgroundPaint(null); 534 plot.setOutlineStroke(null); 535 536 JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); 537 TextTitle seriesTitle = new TextTitle( 538 "Series Title", new Font("SansSerif", Font.BOLD, 12) 539 ); 540 seriesTitle.setPosition(RectangleEdge.BOTTOM); 541 pieChart.setTitle(seriesTitle); 542 pieChart.removeLegend(); 543 pieChart.setBackgroundPaint(null); 544 plot.setPieChart(pieChart); 545 546 if (tooltips) { 547 PieToolTipGenerator tooltipGenerator 548 = new StandardPieToolTipGenerator(); 549 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 550 pp.setToolTipGenerator(tooltipGenerator); 551 } 552 553 if (urls) { 554 PieURLGenerator urlGenerator = new StandardPieURLGenerator(); 555 PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); 556 pp.setURLGenerator(urlGenerator); 557 } 558 559 JFreeChart chart = new JFreeChart( 560 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 561 ); 562 563 return chart; 564 565 } 566 567 /** 568 * Creates a bar chart. The chart object returned by this method uses a 569 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 570 * for the domain axis, a {@link NumberAxis} as the range axis, and a 571 * {@link BarRenderer} as the renderer. 572 * 573 * @param title the chart title (<code>null</code> permitted). 574 * @param categoryAxisLabel the label for the category axis 575 * (<code>null</code> permitted). 576 * @param valueAxisLabel the label for the value axis 577 * (<code>null</code> permitted). 578 * @param dataset the dataset for the chart (<code>null</code> permitted). 579 * @param orientation the plot orientation (horizontal or vertical) 580 * (<code>null</code> not permitted). 581 * @param legend a flag specifying whether or not a legend is required. 582 * @param tooltips configure chart to generate tool tips? 583 * @param urls configure chart to generate URLs? 584 * 585 * @return A bar chart. 586 */ 587 public static JFreeChart createBarChart(String title, 588 String categoryAxisLabel, 589 String valueAxisLabel, 590 CategoryDataset dataset, 591 PlotOrientation orientation, 592 boolean legend, 593 boolean tooltips, 594 boolean urls) { 595 596 if (orientation == null) { 597 throw new IllegalArgumentException("Null 'orientation' argument."); 598 } 599 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 600 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 601 602 BarRenderer renderer = new BarRenderer(); 603 if (orientation == PlotOrientation.HORIZONTAL) { 604 ItemLabelPosition position1 = new ItemLabelPosition( 605 ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT 606 ); 607 renderer.setPositiveItemLabelPosition(position1); 608 ItemLabelPosition position2 = new ItemLabelPosition( 609 ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT 610 ); 611 renderer.setNegativeItemLabelPosition(position2); 612 } 613 else if (orientation == PlotOrientation.VERTICAL) { 614 ItemLabelPosition position1 = new ItemLabelPosition( 615 ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER 616 ); 617 renderer.setPositiveItemLabelPosition(position1); 618 ItemLabelPosition position2 = new ItemLabelPosition( 619 ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER 620 ); 621 renderer.setNegativeItemLabelPosition(position2); 622 } 623 if (tooltips) { 624 renderer.setBaseToolTipGenerator( 625 new StandardCategoryToolTipGenerator() 626 ); 627 } 628 if (urls) { 629 renderer.setBaseItemURLGenerator( 630 new StandardCategoryURLGenerator() 631 ); 632 } 633 634 CategoryPlot plot = new CategoryPlot( 635 dataset, categoryAxis, valueAxis, renderer 636 ); 637 plot.setOrientation(orientation); 638 JFreeChart chart = new JFreeChart( 639 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 640 ); 641 642 return chart; 643 644 } 645 646 /** 647 * Creates a stacked bar chart with default settings. The chart object 648 * returned by this method uses a {@link CategoryPlot} instance as the 649 * plot, with a {@link CategoryAxis} for the domain axis, a 650 * {@link NumberAxis} as the range axis, and a {@link StackedBarRenderer} 651 * as the renderer. 652 * 653 * @param title the chart title (<code>null</code> permitted). 654 * @param domainAxisLabel the label for the category axis 655 * (<code>null</code> permitted). 656 * @param rangeAxisLabel the label for the value axis 657 * (<code>null</code> permitted). 658 * @param dataset the dataset for the chart (<code>null</code> permitted). 659 * @param orientation the orientation of the chart (horizontal or 660 * vertical) (<code>null</code> not permitted). 661 * @param legend a flag specifying whether or not a legend is required. 662 * @param tooltips configure chart to generate tool tips? 663 * @param urls configure chart to generate URLs? 664 * 665 * @return A stacked bar chart. 666 */ 667 public static JFreeChart createStackedBarChart(String title, 668 String domainAxisLabel, 669 String rangeAxisLabel, 670 CategoryDataset dataset, 671 PlotOrientation orientation, 672 boolean legend, 673 boolean tooltips, 674 boolean urls) { 675 676 if (orientation == null) { 677 throw new IllegalArgumentException("Null 'orientation' argument."); 678 } 679 680 CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); 681 ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); 682 683 StackedBarRenderer renderer = new StackedBarRenderer(); 684 if (tooltips) { 685 renderer.setBaseToolTipGenerator( 686 new StandardCategoryToolTipGenerator() 687 ); 688 } 689 if (urls) { 690 renderer.setBaseItemURLGenerator( 691 new StandardCategoryURLGenerator() 692 ); 693 } 694 695 CategoryPlot plot = new CategoryPlot( 696 dataset, categoryAxis, valueAxis, renderer 697 ); 698 plot.setOrientation(orientation); 699 JFreeChart chart = new JFreeChart( 700 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 701 ); 702 703 return chart; 704 705 } 706 707 /** 708 * Creates a bar chart with a 3D effect. The chart object returned by this 709 * method uses a {@link CategoryPlot} instance as the plot, with a 710 * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as 711 * the range axis, and a {@link BarRenderer3D} as the renderer. 712 * 713 * @param title the chart title (<code>null</code> permitted). 714 * @param categoryAxisLabel the label for the category axis 715 * (<code>null</code> permitted). 716 * @param valueAxisLabel the label for the value axis (<code>null</code> 717 * permitted). 718 * @param dataset the dataset for the chart (<code>null</code> permitted). 719 * @param orientation the plot orientation (horizontal or vertical) 720 * (<code>null</code> not permitted). 721 * @param legend a flag specifying whether or not a legend is required. 722 * @param tooltips configure chart to generate tool tips? 723 * @param urls configure chart to generate URLs? 724 * 725 * @return A bar chart with a 3D effect. 726 */ 727 public static JFreeChart createBarChart3D(String title, 728 String categoryAxisLabel, 729 String valueAxisLabel, 730 CategoryDataset dataset, 731 PlotOrientation orientation, 732 boolean legend, 733 boolean tooltips, 734 boolean urls) { 735 736 if (orientation == null) { 737 throw new IllegalArgumentException("Null 'orientation' argument."); 738 } 739 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); 740 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); 741 742 BarRenderer3D renderer = new BarRenderer3D(); 743 if (tooltips) { 744 renderer.setBaseToolTipGenerator( 745 new StandardCategoryToolTipGenerator() 746 ); 747 } 748 if (urls) { 749 renderer.setBaseItemURLGenerator( 750 new StandardCategoryURLGenerator() 751 ); 752 } 753 754 CategoryPlot plot = new CategoryPlot( 755 dataset, categoryAxis, valueAxis, renderer 756 ); 757 plot.setOrientation(orientation); 758 if (orientation == PlotOrientation.HORIZONTAL) { 759 // change rendering order to ensure that bar overlapping is the 760 // right way around 761 plot.setRowRenderingOrder(SortOrder.DESCENDING); 762 plot.setColumnRenderingOrder(SortOrder.DESCENDING); 763 } 764 plot.setForegroundAlpha(0.75f); 765 766 JFreeChart chart = new JFreeChart( 767 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 768 ); 769 770 return chart; 771 772 } 773 774 /** 775 * Creates a stacked bar chart with a 3D effect and default settings. The 776 * chart object returned by this method uses a {@link CategoryPlot} 777 * instance as the plot, with a {@link CategoryAxis3D} for the domain axis, 778 * a {@link NumberAxis3D} as the range axis, and a 779 * {@link StackedBarRenderer3D} as the renderer. 780 * 781 * @param title the chart title (<code>null</code> permitted). 782 * @param categoryAxisLabel the label for the category axis 783 * (<code>null</code> permitted). 784 * @param valueAxisLabel the label for the value axis (<code>null</code> 785 * permitted). 786 * @param dataset the dataset for the chart (<code>null</code> permitted). 787 * @param orientation the orientation (horizontal or vertical) 788 * (<code>null</code> not permitted). 789 * @param legend a flag specifying whether or not a legend is required. 790 * @param tooltips configure chart to generate tool tips? 791 * @param urls configure chart to generate URLs? 792 * 793 * @return A stacked bar chart with a 3D effect. 794 */ 795 public static JFreeChart createStackedBarChart3D(String title, 796 String categoryAxisLabel, 797 String valueAxisLabel, 798 CategoryDataset dataset, 799 PlotOrientation orientation, 800 boolean legend, 801 boolean tooltips, 802 boolean urls) { 803 804 if (orientation == null) { 805 throw new IllegalArgumentException("Null 'orientation' argument."); 806 } 807 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); 808 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); 809 810 // create the renderer... 811 CategoryItemRenderer renderer = new StackedBarRenderer3D(); 812 if (tooltips) { 813 renderer.setBaseToolTipGenerator( 814 new StandardCategoryToolTipGenerator() 815 ); 816 } 817 if (urls) { 818 renderer.setBaseItemURLGenerator( 819 new StandardCategoryURLGenerator() 820 ); 821 } 822 823 // create the plot... 824 CategoryPlot plot = new CategoryPlot( 825 dataset, categoryAxis, valueAxis, renderer 826 ); 827 plot.setOrientation(orientation); 828 if (orientation == PlotOrientation.HORIZONTAL) { 829 // change rendering order to ensure that bar overlapping is the 830 // right way around 831 plot.setColumnRenderingOrder(SortOrder.DESCENDING); 832 } 833 834 // create the chart... 835 JFreeChart chart = new JFreeChart( 836 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 837 ); 838 839 return chart; 840 841 } 842 843 /** 844 * Creates an area chart with default settings. The chart object returned 845 * by this method uses a {@link CategoryPlot} instance as the plot, with a 846 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 847 * range axis, and an {@link AreaRenderer} as the renderer. 848 * 849 * @param title the chart title (<code>null</code> permitted). 850 * @param categoryAxisLabel the label for the category axis 851 * (<code>null</code> permitted). 852 * @param valueAxisLabel the label for the value axis (<code>null</code> 853 * permitted). 854 * @param dataset the dataset for the chart (<code>null</code> permitted). 855 * @param orientation the plot orientation (<code>null</code> not 856 * permitted). 857 * @param legend a flag specifying whether or not a legend is required. 858 * @param tooltips configure chart to generate tool tips? 859 * @param urls configure chart to generate URLs? 860 * 861 * @return An area chart. 862 */ 863 public static JFreeChart createAreaChart(String title, 864 String categoryAxisLabel, 865 String valueAxisLabel, 866 CategoryDataset dataset, 867 PlotOrientation orientation, 868 boolean legend, 869 boolean tooltips, 870 boolean urls) { 871 872 if (orientation == null) { 873 throw new IllegalArgumentException("Null 'orientation' argument."); 874 } 875 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 876 categoryAxis.setCategoryMargin(0.0); 877 878 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 879 880 AreaRenderer renderer = new AreaRenderer(); 881 if (tooltips) { 882 renderer.setBaseToolTipGenerator( 883 new StandardCategoryToolTipGenerator() 884 ); 885 } 886 if (urls) { 887 renderer.setBaseItemURLGenerator( 888 new StandardCategoryURLGenerator() 889 ); 890 } 891 892 CategoryPlot plot = new CategoryPlot( 893 dataset, categoryAxis, valueAxis, renderer 894 ); 895 plot.setOrientation(orientation); 896 JFreeChart chart = new JFreeChart( 897 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 898 ); 899 900 return chart; 901 902 } 903 904 /** 905 * Creates a stacked area chart with default settings. The chart object 906 * returned by this method uses a {@link CategoryPlot} instance as the 907 * plot, with a {@link CategoryAxis} for the domain axis, a 908 * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} 909 * as the renderer. 910 * 911 * @param title the chart title (<code>null</code> permitted). 912 * @param categoryAxisLabel the label for the category axis 913 * (<code>null</code> permitted). 914 * @param valueAxisLabel the label for the value axis (<code>null</code> 915 * permitted). 916 * @param dataset the dataset for the chart (<code>null</code> permitted). 917 * @param orientation the plot orientation (horizontal or vertical) 918 * (<code>null</code> not permitted). 919 * @param legend a flag specifying whether or not a legend is required. 920 * @param tooltips configure chart to generate tool tips? 921 * @param urls configure chart to generate URLs? 922 * 923 * @return A stacked area chart. 924 */ 925 public static JFreeChart createStackedAreaChart(String title, 926 String categoryAxisLabel, 927 String valueAxisLabel, 928 CategoryDataset dataset, 929 PlotOrientation orientation, 930 boolean legend, 931 boolean tooltips, 932 boolean urls) { 933 934 if (orientation == null) { 935 throw new IllegalArgumentException("Null 'orientation' argument."); 936 } 937 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 938 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 939 940 StackedAreaRenderer renderer = new StackedAreaRenderer(); 941 if (tooltips) { 942 renderer.setBaseToolTipGenerator( 943 new StandardCategoryToolTipGenerator() 944 ); 945 } 946 if (urls) { 947 renderer.setBaseItemURLGenerator( 948 new StandardCategoryURLGenerator() 949 ); 950 } 951 952 CategoryPlot plot = new CategoryPlot( 953 dataset, categoryAxis, valueAxis, renderer 954 ); 955 plot.setOrientation(orientation); 956 JFreeChart chart = new JFreeChart( 957 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 958 ); 959 960 return chart; 961 962 } 963 964 /** 965 * Creates a line chart with default settings. The chart object returned 966 * by this method uses a {@link CategoryPlot} instance as the plot, with a 967 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 968 * range axis, and a {@link LineAndShapeRenderer} as the renderer. 969 * 970 * @param title the chart title (<code>null</code> permitted). 971 * @param categoryAxisLabel the label for the category axis 972 * (<code>null</code> permitted). 973 * @param valueAxisLabel the label for the value axis (<code>null</code> 974 * permitted). 975 * @param dataset the dataset for the chart (<code>null</code> permitted). 976 * @param orientation the chart orientation (horizontal or vertical) 977 * (<code>null</code> not permitted). 978 * @param legend a flag specifying whether or not a legend is required. 979 * @param tooltips configure chart to generate tool tips? 980 * @param urls configure chart to generate URLs? 981 * 982 * @return A line chart. 983 */ 984 public static JFreeChart createLineChart(String title, 985 String categoryAxisLabel, 986 String valueAxisLabel, 987 CategoryDataset dataset, 988 PlotOrientation orientation, 989 boolean legend, 990 boolean tooltips, 991 boolean urls) { 992 993 if (orientation == null) { 994 throw new IllegalArgumentException("Null 'orientation' argument."); 995 } 996 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 997 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 998 999 LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); 1000 if (tooltips) { 1001 renderer.setBaseToolTipGenerator( 1002 new StandardCategoryToolTipGenerator() 1003 ); 1004 } 1005 if (urls) { 1006 renderer.setBaseItemURLGenerator( 1007 new StandardCategoryURLGenerator() 1008 ); 1009 } 1010 CategoryPlot plot = new CategoryPlot( 1011 dataset, categoryAxis, valueAxis, renderer 1012 ); 1013 plot.setOrientation(orientation); 1014 JFreeChart chart = new JFreeChart( 1015 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1016 ); 1017 1018 return chart; 1019 1020 } 1021 1022 /** 1023 * Creates a line chart with default settings. The chart object returned by 1024 * this method uses a {@link CategoryPlot} instance as the plot, with a 1025 * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as 1026 * the range axis, and a {@link LineRenderer3D} as the renderer. 1027 * 1028 * @param title the chart title (<code>null</code> permitted). 1029 * @param categoryAxisLabel the label for the category axis 1030 * (<code>null</code> permitted). 1031 * @param valueAxisLabel the label for the value axis (<code>null</code> 1032 * permitted). 1033 * @param dataset the dataset for the chart (<code>null</code> permitted). 1034 * @param orientation the chart orientation (horizontal or vertical) 1035 * (<code>null</code> not permitted). 1036 * @param legend a flag specifying whether or not a legend is required. 1037 * @param tooltips configure chart to generate tool tips? 1038 * @param urls configure chart to generate URLs? 1039 * 1040 * @return A line chart. 1041 */ 1042 public static JFreeChart createLineChart3D(String title, 1043 String categoryAxisLabel, 1044 String valueAxisLabel, 1045 CategoryDataset dataset, 1046 PlotOrientation orientation, 1047 boolean legend, 1048 boolean tooltips, 1049 boolean urls) { 1050 1051 if (orientation == null) { 1052 throw new IllegalArgumentException("Null 'orientation' argument."); 1053 } 1054 CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); 1055 ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); 1056 1057 LineRenderer3D renderer = new LineRenderer3D(); 1058 if (tooltips) { 1059 renderer.setBaseToolTipGenerator( 1060 new StandardCategoryToolTipGenerator() 1061 ); 1062 } 1063 if (urls) { 1064 renderer.setBaseItemURLGenerator( 1065 new StandardCategoryURLGenerator() 1066 ); 1067 } 1068 CategoryPlot plot = new CategoryPlot( 1069 dataset, categoryAxis, valueAxis, renderer 1070 ); 1071 plot.setOrientation(orientation); 1072 JFreeChart chart = new JFreeChart( 1073 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1074 ); 1075 1076 return chart; 1077 1078 } 1079 1080 /** 1081 * Creates a Gantt chart using the supplied attributes plus default values 1082 * where required. The chart object returned by this method uses a 1083 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 1084 * for the domain axis, a {@link DateAxis} as the range axis, and a 1085 * {@link GanttRenderer} as the renderer. 1086 * 1087 * @param title the chart title (<code>null</code> permitted). 1088 * @param categoryAxisLabel the label for the category axis 1089 * (<code>null</code> permitted). 1090 * @param dateAxisLabel the label for the date axis 1091 * (<code>null</code> permitted). 1092 * @param dataset the dataset for the chart (<code>null</code> permitted). 1093 * @param legend a flag specifying whether or not a legend is required. 1094 * @param tooltips configure chart to generate tool tips? 1095 * @param urls configure chart to generate URLs? 1096 * 1097 * @return A Gantt chart. 1098 */ 1099 public static JFreeChart createGanttChart(String title, 1100 String categoryAxisLabel, 1101 String dateAxisLabel, 1102 IntervalCategoryDataset dataset, 1103 boolean legend, 1104 boolean tooltips, 1105 boolean urls) { 1106 1107 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1108 DateAxis dateAxis = new DateAxis(dateAxisLabel); 1109 1110 CategoryItemRenderer renderer = new GanttRenderer(); 1111 if (tooltips) { 1112 renderer.setBaseToolTipGenerator( 1113 new IntervalCategoryToolTipGenerator( 1114 "{3} - {4}", DateFormat.getDateInstance() 1115 ) 1116 ); 1117 } 1118 if (urls) { 1119 renderer.setBaseItemURLGenerator( 1120 new StandardCategoryURLGenerator() 1121 ); 1122 } 1123 1124 CategoryPlot plot = new CategoryPlot( 1125 dataset, categoryAxis, dateAxis, renderer 1126 ); 1127 plot.setOrientation(PlotOrientation.HORIZONTAL); 1128 JFreeChart chart = new JFreeChart( 1129 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1130 ); 1131 1132 return chart; 1133 1134 } 1135 1136 /** 1137 * Creates a waterfall chart. The chart object returned by this method 1138 * uses a {@link CategoryPlot} instance as the plot, with a 1139 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the 1140 * range axis, and a {@link WaterfallBarRenderer} as the renderer. 1141 * 1142 * @param title the chart title (<code>null</code> permitted). 1143 * @param categoryAxisLabel the label for the category axis 1144 * (<code>null</code> permitted). 1145 * @param valueAxisLabel the label for the value axis (<code>null</code> 1146 * permitted). 1147 * @param dataset the dataset for the chart (<code>null</code> permitted). 1148 * @param orientation the plot orientation (horizontal or vertical) 1149 * (<code>null</code> NOT permitted). 1150 * @param legend a flag specifying whether or not a legend is required. 1151 * @param tooltips configure chart to generate tool tips? 1152 * @param urls configure chart to generate URLs? 1153 * 1154 * @return A waterfall chart. 1155 */ 1156 public static JFreeChart createWaterfallChart(String title, 1157 String categoryAxisLabel, 1158 String valueAxisLabel, 1159 CategoryDataset dataset, 1160 PlotOrientation orientation, 1161 boolean legend, 1162 boolean tooltips, 1163 boolean urls) { 1164 1165 if (orientation == null) { 1166 throw new IllegalArgumentException("Null 'orientation' argument."); 1167 } 1168 CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); 1169 categoryAxis.setCategoryMargin(0.0); 1170 1171 ValueAxis valueAxis = new NumberAxis(valueAxisLabel); 1172 1173 WaterfallBarRenderer renderer = new WaterfallBarRenderer(); 1174 if (orientation == PlotOrientation.HORIZONTAL) { 1175 ItemLabelPosition position = new ItemLabelPosition( 1176 ItemLabelAnchor.CENTER, TextAnchor.CENTER, 1177 TextAnchor.CENTER, Math.PI / 2.0 1178 ); 1179 renderer.setPositiveItemLabelPosition(position); 1180 renderer.setNegativeItemLabelPosition(position); 1181 } 1182 else if (orientation == PlotOrientation.VERTICAL) { 1183 ItemLabelPosition position = new ItemLabelPosition( 1184 ItemLabelAnchor.CENTER, TextAnchor.CENTER, 1185 TextAnchor.CENTER, 0.0 1186 ); 1187 renderer.setPositiveItemLabelPosition(position); 1188 renderer.setNegativeItemLabelPosition(position); 1189 } 1190 if (tooltips) { 1191 StandardCategoryToolTipGenerator generator 1192 = new StandardCategoryToolTipGenerator(); 1193 renderer.setBaseToolTipGenerator(generator); 1194 } 1195 if (urls) { 1196 renderer.setBaseItemURLGenerator( 1197 new StandardCategoryURLGenerator() 1198 ); 1199 } 1200 1201 CategoryPlot plot = new CategoryPlot( 1202 dataset, categoryAxis, valueAxis, renderer 1203 ); 1204 plot.clearRangeMarkers(); 1205 Marker baseline = new ValueMarker(0.0); 1206 baseline.setPaint(Color.black); 1207 plot.addRangeMarker(baseline, Layer.FOREGROUND); 1208 plot.setOrientation(orientation); 1209 JFreeChart chart = new JFreeChart( 1210 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1211 ); 1212 1213 return chart; 1214 1215 } 1216 1217 /** 1218 * Creates a polar plot for the specified dataset (x-values interpreted as 1219 * angles in degrees). The chart object returned by this method uses a 1220 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for 1221 * the radial axis. 1222 * 1223 * @param title the chart title (<code>null</code> permitted). 1224 * @param dataset the dataset (<code>null</code> permitted). 1225 * @param legend legend required? 1226 * @param tooltips tooltips required? 1227 * @param urls URLs required? 1228 * 1229 * @return A chart. 1230 */ 1231 public static JFreeChart createPolarChart(String title, 1232 XYDataset dataset, 1233 boolean legend, 1234 boolean tooltips, 1235 boolean urls) { 1236 1237 PolarPlot plot = new PolarPlot(); 1238 plot.setDataset(dataset); 1239 NumberAxis rangeAxis = new NumberAxis(); 1240 rangeAxis.setAxisLineVisible(false); 1241 rangeAxis.setTickMarksVisible(false); 1242 rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); 1243 plot.setAxis(rangeAxis); 1244 plot.setRenderer(new DefaultPolarItemRenderer()); 1245 JFreeChart chart = new JFreeChart( 1246 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1247 ); 1248 return chart; 1249 1250 } 1251 1252 /** 1253 * Creates a scatter plot with default settings. The chart object 1254 * returned by this method uses an {@link XYPlot} instance as the plot, 1255 * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} 1256 * as the range axis, and an {@link XYLineAndShapeRenderer} as the 1257 * renderer. 1258 * 1259 * @param title the chart title (<code>null</code> permitted). 1260 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 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 plot 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 A scatter plot. 1270 */ 1271 public static JFreeChart createScatterPlot(String title, String xAxisLabel, 1272 String yAxisLabel, XYDataset dataset, PlotOrientation orientation, 1273 boolean legend, boolean tooltips, boolean urls) { 1274 1275 if (orientation == null) { 1276 throw new IllegalArgumentException("Null 'orientation' argument."); 1277 } 1278 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1279 xAxis.setAutoRangeIncludesZero(false); 1280 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1281 yAxis.setAutoRangeIncludesZero(false); 1282 1283 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1284 1285 XYToolTipGenerator toolTipGenerator = null; 1286 if (tooltips) { 1287 toolTipGenerator = new StandardXYToolTipGenerator(); 1288 } 1289 1290 XYURLGenerator urlGenerator = null; 1291 if (urls) { 1292 urlGenerator = new StandardXYURLGenerator(); 1293 } 1294 XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); 1295 renderer.setBaseToolTipGenerator(toolTipGenerator); 1296 renderer.setURLGenerator(urlGenerator); 1297 plot.setRenderer(renderer); 1298 plot.setOrientation(orientation); 1299 1300 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, 1301 plot, legend); 1302 return chart; 1303 1304 } 1305 1306 /** 1307 * Creates and returns a default instance of an XY bar chart. 1308 * <P> 1309 * The chart object returned by this method uses an {@link XYPlot} instance 1310 * as the plot, with a {@link DateAxis} for the domain axis, a 1311 * {@link NumberAxis} as the range axis, and a {@link XYBarRenderer} as the 1312 * renderer. 1313 * 1314 * @param title the chart title (<code>null</code> permitted). 1315 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1316 * @param dateAxis make the domain axis display dates? 1317 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1318 * @param dataset the dataset for the chart (<code>null</code> permitted). 1319 * @param orientation the orientation (horizontal or vertical) 1320 * (<code>null</code> NOT permitted). 1321 * @param legend a flag specifying whether or not a legend is required. 1322 * @param tooltips configure chart to generate tool tips? 1323 * @param urls configure chart to generate URLs? 1324 * 1325 * @return An XY bar chart. 1326 */ 1327 public static JFreeChart createXYBarChart(String title, 1328 String xAxisLabel, 1329 boolean dateAxis, 1330 String yAxisLabel, 1331 IntervalXYDataset dataset, 1332 PlotOrientation orientation, 1333 boolean legend, 1334 boolean tooltips, 1335 boolean urls) { 1336 1337 if (orientation == null) { 1338 throw new IllegalArgumentException("Null 'orientation' argument."); 1339 } 1340 ValueAxis domainAxis = null; 1341 if (dateAxis) { 1342 domainAxis = new DateAxis(xAxisLabel); 1343 } 1344 else { 1345 NumberAxis axis = new NumberAxis(xAxisLabel); 1346 axis.setAutoRangeIncludesZero(false); 1347 domainAxis = axis; 1348 } 1349 ValueAxis valueAxis = new NumberAxis(yAxisLabel); 1350 1351 XYBarRenderer renderer = new XYBarRenderer(); 1352 if (tooltips) { 1353 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1354 } 1355 if (urls) { 1356 renderer.setURLGenerator(new StandardXYURLGenerator()); 1357 } 1358 1359 XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer); 1360 plot.setOrientation(orientation); 1361 1362 JFreeChart chart = new JFreeChart( 1363 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1364 ); 1365 1366 return chart; 1367 1368 } 1369 1370 /** 1371 * Creates an area chart using an {@link XYDataset}. 1372 * <P> 1373 * The chart object returned by this method uses an {@link XYPlot} instance 1374 * as the plot, with a {@link NumberAxis} for the domain axis, a 1375 * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as 1376 * the renderer. 1377 * 1378 * @param title the chart title (<code>null</code> permitted). 1379 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1380 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1381 * @param dataset the dataset for the chart (<code>null</code> permitted). 1382 * @param orientation the plot orientation (horizontal or vertical) 1383 * (<code>null</code> NOT permitted). 1384 * @param legend a flag specifying whether or not a legend is required. 1385 * @param tooltips configure chart to generate tool tips? 1386 * @param urls configure chart to generate URLs? 1387 * 1388 * @return An XY area chart. 1389 */ 1390 public static JFreeChart createXYAreaChart(String title, 1391 String xAxisLabel, 1392 String yAxisLabel, 1393 XYDataset dataset, 1394 PlotOrientation orientation, 1395 boolean legend, 1396 boolean tooltips, 1397 boolean urls) { 1398 1399 if (orientation == null) { 1400 throw new IllegalArgumentException("Null 'orientation' argument."); 1401 } 1402 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1403 xAxis.setAutoRangeIncludesZero(false); 1404 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1405 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1406 plot.setOrientation(orientation); 1407 plot.setForegroundAlpha(0.5f); 1408 1409 XYToolTipGenerator tipGenerator = null; 1410 if (tooltips) { 1411 tipGenerator = new StandardXYToolTipGenerator(); 1412 } 1413 1414 XYURLGenerator urlGenerator = null; 1415 if (urls) { 1416 urlGenerator = new StandardXYURLGenerator(); 1417 } 1418 1419 plot.setRenderer( 1420 new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator) 1421 ); 1422 JFreeChart chart = new JFreeChart( 1423 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1424 ); 1425 1426 return chart; 1427 1428 } 1429 1430 /** 1431 * Creates a stacked XY area plot. The chart object returned by this 1432 * method uses an {@link XYPlot} instance as the plot, with a 1433 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the 1434 * range axis, and a {@link StackedXYAreaRenderer} as the renderer. 1435 * 1436 * @param title the chart title (<code>null</code> permitted). 1437 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1438 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1439 * @param dataset the dataset for the chart (<code>null</code> permitted). 1440 * @param orientation the plot orientation (horizontal or vertical) 1441 * (<code>null</code> NOT permitted). 1442 * @param legend a flag specifying whether or not a legend is required. 1443 * @param tooltips configure chart to generate tool tips? 1444 * @param urls configure chart to generate URLs? 1445 * 1446 * @return A stacked XY area chart. 1447 */ 1448 public static JFreeChart createStackedXYAreaChart(String title, 1449 String xAxisLabel, 1450 String yAxisLabel, 1451 TableXYDataset dataset, 1452 PlotOrientation orientation, 1453 boolean legend, 1454 boolean tooltips, 1455 boolean urls) { 1456 1457 if (orientation == null) { 1458 throw new IllegalArgumentException("Null 'orientation' argument."); 1459 } 1460 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1461 xAxis.setAutoRangeIncludesZero(false); 1462 xAxis.setLowerMargin(0.0); 1463 xAxis.setUpperMargin(0.0); 1464 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1465 XYToolTipGenerator toolTipGenerator = null; 1466 if (tooltips) { 1467 toolTipGenerator = new StandardXYToolTipGenerator(); 1468 } 1469 1470 XYURLGenerator urlGenerator = null; 1471 if (urls) { 1472 urlGenerator = new StandardXYURLGenerator(); 1473 } 1474 StackedXYAreaRenderer renderer = new StackedXYAreaRenderer( 1475 XYAreaRenderer.AREA, toolTipGenerator, urlGenerator 1476 ); 1477 renderer.setOutline(true); 1478 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1479 plot.setOrientation(orientation); 1480 1481 plot.setRangeAxis(yAxis); // forces recalculation of the axis range 1482 1483 JFreeChart chart = new JFreeChart( 1484 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1485 ); 1486 return chart; 1487 1488 } 1489 1490 /** 1491 * Creates a line chart (based on an {@link XYDataset}) with default 1492 * settings. 1493 * 1494 * @param title the chart title (<code>null</code> permitted). 1495 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1496 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1497 * @param dataset the dataset for the chart (<code>null</code> permitted). 1498 * @param orientation the plot orientation (horizontal or vertical) 1499 * (<code>null</code> NOT permitted). 1500 * @param legend a flag specifying whether or not a legend is required. 1501 * @param tooltips configure chart to generate tool tips? 1502 * @param urls configure chart to generate URLs? 1503 * 1504 * @return The chart. 1505 */ 1506 public static JFreeChart createXYLineChart(String title, 1507 String xAxisLabel, 1508 String yAxisLabel, 1509 XYDataset dataset, 1510 PlotOrientation orientation, 1511 boolean legend, 1512 boolean tooltips, 1513 boolean urls) { 1514 1515 if (orientation == null) { 1516 throw new IllegalArgumentException("Null 'orientation' argument."); 1517 } 1518 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1519 xAxis.setAutoRangeIncludesZero(false); 1520 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1521 XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); 1522 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1523 plot.setOrientation(orientation); 1524 if (tooltips) { 1525 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1526 } 1527 if (urls) { 1528 renderer.setURLGenerator(new StandardXYURLGenerator()); 1529 } 1530 1531 JFreeChart chart = new JFreeChart( 1532 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1533 ); 1534 1535 return chart; 1536 1537 } 1538 1539 /** 1540 * Creates a 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 createXYStepChart(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 DateAxis xAxis = new DateAxis(xAxisLabel); 1567 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1568 yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 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 1580 = new XYStepRenderer(toolTipGenerator, urlGenerator); 1581 1582 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1583 plot.setRenderer(renderer); 1584 plot.setOrientation(orientation); 1585 plot.setDomainCrosshairVisible(false); 1586 plot.setRangeCrosshairVisible(false); 1587 JFreeChart chart = new JFreeChart( 1588 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1589 ); 1590 return chart; 1591 1592 } 1593 1594 /** 1595 * Creates a filled stepped XY plot with default settings. 1596 * 1597 * @param title the chart title (<code>null</code> permitted). 1598 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1599 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1600 * @param dataset the dataset for the chart (<code>null</code> permitted). 1601 * @param orientation the plot orientation (horizontal or vertical) 1602 * (<code>null</code> NOT permitted). 1603 * @param legend a flag specifying whether or not a legend is required. 1604 * @param tooltips configure chart to generate tool tips? 1605 * @param urls configure chart to generate URLs? 1606 * 1607 * @return A chart. 1608 */ 1609 public static JFreeChart createXYStepAreaChart(String title, 1610 String xAxisLabel, 1611 String yAxisLabel, 1612 XYDataset dataset, 1613 PlotOrientation orientation, 1614 boolean legend, 1615 boolean tooltips, 1616 boolean urls) { 1617 1618 if (orientation == null) { 1619 throw new IllegalArgumentException("Null 'orientation' argument."); 1620 } 1621 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1622 xAxis.setAutoRangeIncludesZero(false); 1623 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1624 1625 XYToolTipGenerator toolTipGenerator = null; 1626 if (tooltips) { 1627 toolTipGenerator = new StandardXYToolTipGenerator(); 1628 } 1629 1630 XYURLGenerator urlGenerator = null; 1631 if (urls) { 1632 urlGenerator = new StandardXYURLGenerator(); 1633 } 1634 XYItemRenderer renderer = new XYStepAreaRenderer( 1635 XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator 1636 ); 1637 1638 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1639 plot.setRenderer(renderer); 1640 plot.setOrientation(orientation); 1641 plot.setDomainCrosshairVisible(false); 1642 plot.setRangeCrosshairVisible(false); 1643 JFreeChart chart = new JFreeChart( 1644 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1645 ); 1646 return chart; 1647 } 1648 1649 /** 1650 * Creates and returns a time series chart. A time series chart is an 1651 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a 1652 * {@link NumberAxis} for the y-axis. The default renderer is an 1653 * {@link XYLineAndShapeRenderer}. 1654 * <P> 1655 * A convenient dataset to use with this chart is a 1656 * {@link org.jfree.data.time.TimeSeriesCollection}. 1657 * 1658 * @param title the chart title (<code>null</code> permitted). 1659 * @param timeAxisLabel a label for the time axis (<code>null</code> 1660 * permitted). 1661 * @param valueAxisLabel a label for the value axis (<code>null</code> 1662 * permitted). 1663 * @param dataset the dataset for the chart (<code>null</code> permitted). 1664 * @param legend a flag specifying whether or not a legend is required. 1665 * @param tooltips configure chart to generate tool tips? 1666 * @param urls configure chart to generate URLs? 1667 * 1668 * @return A time series chart. 1669 */ 1670 public static JFreeChart createTimeSeriesChart(String title, 1671 String timeAxisLabel, 1672 String valueAxisLabel, 1673 XYDataset dataset, 1674 boolean legend, 1675 boolean tooltips, 1676 boolean urls) { 1677 1678 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1679 timeAxis.setLowerMargin(0.02); // reduce the default margins 1680 timeAxis.setUpperMargin(0.02); 1681 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1682 valueAxis.setAutoRangeIncludesZero(false); // override default 1683 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1684 1685 XYToolTipGenerator toolTipGenerator = null; 1686 if (tooltips) { 1687 toolTipGenerator 1688 = StandardXYToolTipGenerator.getTimeSeriesInstance(); 1689 } 1690 1691 XYURLGenerator urlGenerator = null; 1692 if (urls) { 1693 urlGenerator = new StandardXYURLGenerator(); 1694 } 1695 1696 XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, 1697 false); 1698 renderer.setBaseToolTipGenerator(toolTipGenerator); 1699 renderer.setURLGenerator(urlGenerator); 1700 plot.setRenderer(renderer); 1701 1702 JFreeChart chart = new JFreeChart( 1703 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1704 ); 1705 return chart; 1706 1707 } 1708 1709 /** 1710 * Creates and returns a default instance of a candlesticks chart. 1711 * 1712 * @param title the chart title (<code>null</code> permitted). 1713 * @param timeAxisLabel a label for the time axis (<code>null</code> 1714 * permitted). 1715 * @param valueAxisLabel a label for the value axis (<code>null</code> 1716 * permitted). 1717 * @param dataset the dataset for the chart (<code>null</code> permitted). 1718 * @param legend a flag specifying whether or not a legend is required. 1719 * 1720 * @return A candlestick chart. 1721 */ 1722 public static JFreeChart createCandlestickChart(String title, 1723 String timeAxisLabel, 1724 String valueAxisLabel, 1725 OHLCDataset dataset, 1726 boolean legend) { 1727 1728 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1729 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1730 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); 1731 plot.setRenderer(new CandlestickRenderer()); 1732 JFreeChart chart = new JFreeChart( 1733 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1734 ); 1735 return chart; 1736 1737 } 1738 1739 /** 1740 * Creates and returns a default instance of a high-low-open-close chart. 1741 * 1742 * @param title the chart title (<code>null</code> permitted). 1743 * @param timeAxisLabel a label for the time axis (<code>null</code> 1744 * permitted). 1745 * @param valueAxisLabel a label for the value axis (<code>null</code> 1746 * permitted). 1747 * @param dataset the dataset for the chart (<code>null</code> permitted). 1748 * @param legend a flag specifying whether or not a legend is required. 1749 * 1750 * @return A high-low-open-close chart. 1751 */ 1752 public static JFreeChart createHighLowChart(String title, 1753 String timeAxisLabel, 1754 String valueAxisLabel, 1755 OHLCDataset dataset, 1756 boolean legend) { 1757 1758 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1759 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1760 HighLowRenderer renderer = new HighLowRenderer(); 1761 renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); 1762 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1763 JFreeChart chart = new JFreeChart( 1764 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1765 ); 1766 return chart; 1767 1768 } 1769 1770 /** 1771 * Creates and returns a default instance of a high-low-open-close chart 1772 * with a special timeline. This timeline can be a 1773 * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday 1774 * through Friday timeline that will remove Saturdays and Sundays from 1775 * the axis. 1776 * 1777 * @param title the chart title (<code>null</code> permitted). 1778 * @param timeAxisLabel a label for the time axis (<code>null</code> 1779 * permitted). 1780 * @param valueAxisLabel a label for the value axis (<code>null</code> 1781 * permitted). 1782 * @param dataset the dataset for the chart (<code>null</code> permitted). 1783 * @param timeline the timeline. 1784 * @param legend a flag specifying whether or not a legend is required. 1785 * 1786 * @return A high-low-open-close chart. 1787 */ 1788 public static JFreeChart createHighLowChart(String title, 1789 String timeAxisLabel, 1790 String valueAxisLabel, 1791 OHLCDataset dataset, 1792 Timeline timeline, 1793 boolean legend) { 1794 1795 DateAxis timeAxis = new DateAxis(timeAxisLabel); 1796 timeAxis.setTimeline(timeline); 1797 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1798 HighLowRenderer renderer = new HighLowRenderer(); 1799 renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); 1800 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1801 JFreeChart chart = new JFreeChart( 1802 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1803 ); 1804 return chart; 1805 1806 } 1807 1808 /** 1809 * Creates a bubble chart with default settings. The chart is composed of 1810 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, 1811 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} 1812 * to draw the data items. 1813 * 1814 * @param title the chart title (<code>null</code> permitted). 1815 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). 1816 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). 1817 * @param dataset the dataset for the chart (<code>null</code> permitted). 1818 * @param orientation the orientation (horizontal or vertical) 1819 * (<code>null</code> NOT permitted). 1820 * @param legend a flag specifying whether or not a legend is required. 1821 * @param tooltips configure chart to generate tool tips? 1822 * @param urls configure chart to generate URLs? 1823 * 1824 * @return A bubble chart. 1825 */ 1826 public static JFreeChart createBubbleChart(String title, 1827 String xAxisLabel, 1828 String yAxisLabel, 1829 XYZDataset dataset, 1830 PlotOrientation orientation, 1831 boolean legend, 1832 boolean tooltips, 1833 boolean urls) { 1834 1835 if (orientation == null) { 1836 throw new IllegalArgumentException("Null 'orientation' argument."); 1837 } 1838 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1839 xAxis.setAutoRangeIncludesZero(false); 1840 NumberAxis yAxis = new NumberAxis(yAxisLabel); 1841 yAxis.setAutoRangeIncludesZero(false); 1842 1843 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); 1844 1845 XYItemRenderer renderer = new XYBubbleRenderer( 1846 XYBubbleRenderer.SCALE_ON_RANGE_AXIS 1847 ); 1848 if (tooltips) { 1849 renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); 1850 } 1851 if (urls) { 1852 renderer.setURLGenerator(new StandardXYZURLGenerator()); 1853 } 1854 plot.setRenderer(renderer); 1855 plot.setOrientation(orientation); 1856 1857 JFreeChart chart = new JFreeChart( 1858 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1859 ); 1860 1861 return chart; 1862 1863 } 1864 1865 /** 1866 * Creates a histogram chart. This chart is constructed with an 1867 * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range 1868 * axes are {@link NumberAxis} instances. 1869 * 1870 * @param title the chart title (<code>null</code> permitted). 1871 * @param xAxisLabel the x axis label (<code>null</code> permitted). 1872 * @param yAxisLabel the y axis label (<code>null</code> permitted). 1873 * @param dataset the dataset (<code>null</code> permitted). 1874 * @param orientation the orientation (horizontal or vertical) 1875 * (<code>null</code> NOT permitted). 1876 * @param legend create a legend? 1877 * @param tooltips display tooltips? 1878 * @param urls generate URLs? 1879 * 1880 * @return The chart. 1881 */ 1882 public static JFreeChart createHistogram(String title, 1883 String xAxisLabel, 1884 String yAxisLabel, 1885 IntervalXYDataset dataset, 1886 PlotOrientation orientation, 1887 boolean legend, 1888 boolean tooltips, 1889 boolean urls) { 1890 1891 if (orientation == null) { 1892 throw new IllegalArgumentException("Null 'orientation' argument."); 1893 } 1894 NumberAxis xAxis = new NumberAxis(xAxisLabel); 1895 xAxis.setAutoRangeIncludesZero(false); 1896 ValueAxis yAxis = new NumberAxis(yAxisLabel); 1897 1898 XYItemRenderer renderer = new XYBarRenderer(); 1899 if (tooltips) { 1900 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1901 } 1902 if (urls) { 1903 renderer.setURLGenerator(new StandardXYURLGenerator()); 1904 } 1905 1906 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1907 plot.setOrientation(orientation); 1908 JFreeChart chart = new JFreeChart( 1909 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1910 ); 1911 return chart; 1912 1913 } 1914 1915 /** 1916 * Creates and returns a default instance of a box and whisker chart. 1917 * 1918 * @param title the chart title (<code>null</code> permitted). 1919 * @param timeAxisLabel a label for the time axis (<code>null</code> 1920 * permitted). 1921 * @param valueAxisLabel a label for the value axis (<code>null</code> 1922 * permitted). 1923 * @param dataset the dataset for the chart (<code>null</code> permitted). 1924 * @param legend a flag specifying whether or not a legend is required. 1925 * 1926 * @return A box and whisker chart. 1927 */ 1928 public static JFreeChart createBoxAndWhiskerChart(String title, 1929 String timeAxisLabel, 1930 String valueAxisLabel, 1931 BoxAndWhiskerXYDataset dataset, 1932 boolean legend) { 1933 1934 ValueAxis timeAxis = new DateAxis(timeAxisLabel); 1935 NumberAxis valueAxis = new NumberAxis(valueAxisLabel); 1936 valueAxis.setAutoRangeIncludesZero(false); 1937 XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0); 1938 XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); 1939 return new JFreeChart( 1940 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1941 ); 1942 1943 } 1944 1945 /** 1946 * Creates a wind plot with default settings. 1947 * 1948 * @param title the chart title (<code>null</code> permitted). 1949 * @param xAxisLabel a label for the x-axis (<code>null</code> permitted). 1950 * @param yAxisLabel a label for the y-axis (<code>null</code> permitted). 1951 * @param dataset the dataset for the chart (<code>null</code> permitted). 1952 * @param legend a flag that controls whether or not a legend is created. 1953 * @param tooltips configure chart to generate tool tips? 1954 * @param urls configure chart to generate URLs? 1955 * 1956 * @return A wind plot. 1957 * 1958 */ 1959 public static JFreeChart createWindPlot(String title, 1960 String xAxisLabel, 1961 String yAxisLabel, 1962 WindDataset dataset, 1963 boolean legend, 1964 boolean tooltips, 1965 boolean urls) { 1966 1967 ValueAxis xAxis = new DateAxis(xAxisLabel); 1968 ValueAxis yAxis = new NumberAxis(yAxisLabel); 1969 yAxis.setRange(-12.0, 12.0); 1970 1971 WindItemRenderer renderer = new WindItemRenderer(); 1972 if (tooltips) { 1973 renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); 1974 } 1975 if (urls) { 1976 renderer.setURLGenerator(new StandardXYURLGenerator()); 1977 } 1978 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 1979 JFreeChart chart = new JFreeChart( 1980 title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend 1981 ); 1982 1983 return chart; 1984 1985 } 1986 1987 /** 1988 * Creates a wafer map chart. 1989 * 1990 * @param title the chart title (<code>null</code> permitted). 1991 * @param dataset the dataset (<code>null</code> permitted). 1992 * @param orientation the plot orientation (horizontal or vertical) 1993 * (<code>null</code> NOT permitted. 1994 * @param legend display a legend? 1995 * @param tooltips generate tooltips? 1996 * @param urls generate URLs? 1997 * 1998 * @return A wafer map chart. 1999 */ 2000 public static JFreeChart createWaferMapChart(String title, 2001 WaferMapDataset dataset, 2002 PlotOrientation orientation, 2003 boolean legend, 2004 boolean tooltips, 2005 boolean urls) { 2006 2007 if (orientation == null) { 2008 throw new IllegalArgumentException("Null 'orientation' argument."); 2009 } 2010 WaferMapPlot plot = new WaferMapPlot(dataset); 2011 WaferMapRenderer renderer = new WaferMapRenderer(); 2012 plot.setRenderer(renderer); 2013 2014 JFreeChart chart = new JFreeChart( 2015 title, 2016 JFreeChart.DEFAULT_TITLE_FONT, 2017 plot, 2018 legend 2019 ); 2020 2021 return chart; 2022 } 2023 2024 }