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