1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.awt.Color ; 31 import java.awt.Font ; 32 import java.awt.Paint ; 33 import java.text.DateFormat ; 34 import java.text.DecimalFormat ; 35 import java.text.NumberFormat ; 36 import java.text.SimpleDateFormat ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 import java.util.Map ; 40 import java.util.SortedSet ; 41 42 import net.sf.jasperreports.charts.JRAreaPlot; 43 import net.sf.jasperreports.charts.JRBar3DPlot; 44 import net.sf.jasperreports.charts.JRBarPlot; 45 import net.sf.jasperreports.charts.JRBubblePlot; 46 import net.sf.jasperreports.charts.JRCandlestickPlot; 47 import net.sf.jasperreports.charts.JRCategoryDataset; 48 import net.sf.jasperreports.charts.JRChartAxis; 49 import net.sf.jasperreports.charts.JRDataRange; 50 import net.sf.jasperreports.charts.JRHighLowDataset; 51 import net.sf.jasperreports.charts.JRHighLowPlot; 52 import net.sf.jasperreports.charts.JRLinePlot; 53 import net.sf.jasperreports.charts.JRMeterPlot; 54 import net.sf.jasperreports.charts.JRMultiAxisPlot; 55 import net.sf.jasperreports.charts.JRPie3DPlot; 56 import net.sf.jasperreports.charts.JRPieDataset; 57 import net.sf.jasperreports.charts.JRPiePlot; 58 import net.sf.jasperreports.charts.JRScatterPlot; 59 import net.sf.jasperreports.charts.JRThermometerPlot; 60 import net.sf.jasperreports.charts.JRTimePeriodDataset; 61 import net.sf.jasperreports.charts.JRTimeSeriesDataset; 62 import net.sf.jasperreports.charts.JRTimeSeriesPlot; 63 import net.sf.jasperreports.charts.JRValueDataset; 64 import net.sf.jasperreports.charts.JRValueDisplay; 65 import net.sf.jasperreports.charts.JRXyDataset; 66 import net.sf.jasperreports.charts.JRXyzDataset; 67 import net.sf.jasperreports.charts.fill.JRFillAreaPlot; 68 import net.sf.jasperreports.charts.fill.JRFillBar3DPlot; 69 import net.sf.jasperreports.charts.fill.JRFillBarPlot; 70 import net.sf.jasperreports.charts.fill.JRFillCategoryDataset; 71 import net.sf.jasperreports.charts.fill.JRFillChartAxis; 72 import net.sf.jasperreports.charts.fill.JRFillHighLowDataset; 73 import net.sf.jasperreports.charts.fill.JRFillLinePlot; 74 import net.sf.jasperreports.charts.fill.JRFillMeterPlot; 75 import net.sf.jasperreports.charts.fill.JRFillMultiAxisPlot; 76 import net.sf.jasperreports.charts.fill.JRFillPie3DPlot; 77 import net.sf.jasperreports.charts.fill.JRFillPieDataset; 78 import net.sf.jasperreports.charts.fill.JRFillThermometerPlot; 79 import net.sf.jasperreports.charts.fill.JRFillTimePeriodDataset; 80 import net.sf.jasperreports.charts.fill.JRFillTimeSeriesDataset; 81 import net.sf.jasperreports.charts.fill.JRFillXyDataset; 82 import net.sf.jasperreports.charts.fill.JRFillXyzDataset; 83 import net.sf.jasperreports.charts.util.JRMeterInterval; 84 import net.sf.jasperreports.engine.JRAbstractChartCustomizer; 85 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 86 import net.sf.jasperreports.engine.JRBox; 87 import net.sf.jasperreports.engine.JRChart; 88 import net.sf.jasperreports.engine.JRChartCustomizer; 89 import net.sf.jasperreports.engine.JRChartDataset; 90 import net.sf.jasperreports.engine.JRChartPlot; 91 import net.sf.jasperreports.engine.JRChild; 92 import net.sf.jasperreports.engine.JRElement; 93 import net.sf.jasperreports.engine.JRException; 94 import net.sf.jasperreports.engine.JRExpression; 95 import net.sf.jasperreports.engine.JRExpressionCollector; 96 import net.sf.jasperreports.engine.JRFont; 97 import net.sf.jasperreports.engine.JRGroup; 98 import net.sf.jasperreports.engine.JRHyperlinkParameter; 99 import net.sf.jasperreports.engine.JRPrintElement; 100 import net.sf.jasperreports.engine.JRPrintHyperlinkParameters; 101 import net.sf.jasperreports.engine.JRPrintImage; 102 import net.sf.jasperreports.engine.JRRenderable; 103 import net.sf.jasperreports.engine.JRRuntimeException; 104 import net.sf.jasperreports.engine.JRStyle; 105 import net.sf.jasperreports.engine.JRChartPlot.JRSeriesColor; 106 import net.sf.jasperreports.engine.util.JRClassLoader; 107 import net.sf.jasperreports.engine.util.JRFontUtil; 108 import net.sf.jasperreports.engine.util.JRStyleResolver; 109 import net.sf.jasperreports.engine.xml.JRXmlWriter; 110 import net.sf.jasperreports.renderers.JFreeChartRenderer; 111 import net.sf.jasperreports.renderers.JRCategoryChartImageMapRenderer; 112 import net.sf.jasperreports.renderers.JRHighLowChartImageMapRenderer; 113 import net.sf.jasperreports.renderers.JRPieChartImageMapRenderer; 114 import net.sf.jasperreports.renderers.JRTimePeriodChartImageMapRenderer; 115 import net.sf.jasperreports.renderers.JRTimeSeriesChartImageMapRenderer; 116 import net.sf.jasperreports.renderers.JRXYChartImageMapRenderer; 117 118 import org.jfree.chart.ChartFactory; 119 import org.jfree.chart.JFreeChart; 120 import org.jfree.chart.axis.Axis; 121 import org.jfree.chart.axis.AxisLocation; 122 import org.jfree.chart.axis.CategoryAxis; 123 import org.jfree.chart.axis.CategoryLabelPositions; 124 import org.jfree.chart.axis.DateAxis; 125 import org.jfree.chart.axis.NumberAxis; 126 import org.jfree.chart.labels.PieSectionLabelGenerator; 127 import org.jfree.chart.plot.CategoryPlot; 128 import org.jfree.chart.plot.DefaultDrawingSupplier; 129 import org.jfree.chart.plot.DialShape; 130 import org.jfree.chart.plot.MeterInterval; 131 import org.jfree.chart.plot.MeterPlot; 132 import org.jfree.chart.plot.PiePlot; 133 import org.jfree.chart.plot.PiePlot3D; 134 import org.jfree.chart.plot.Plot; 135 import org.jfree.chart.plot.ThermometerPlot; 136 import org.jfree.chart.plot.XYPlot; 137 import org.jfree.chart.renderer.category.BarRenderer3D; 138 import org.jfree.chart.renderer.category.CategoryItemRenderer; 139 import org.jfree.chart.renderer.category.LineAndShapeRenderer; 140 import org.jfree.chart.renderer.category.StackedBarRenderer3D; 141 import org.jfree.chart.renderer.xy.CandlestickRenderer; 142 import org.jfree.chart.renderer.xy.HighLowRenderer; 143 import org.jfree.chart.renderer.xy.XYBubbleRenderer; 144 import org.jfree.chart.renderer.xy.XYItemRenderer; 145 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 146 import org.jfree.chart.title.TextTitle; 147 import org.jfree.data.Range; 148 import org.jfree.data.category.CategoryDataset; 149 import org.jfree.data.general.PieDataset; 150 import org.jfree.data.general.ValueDataset; 151 import org.jfree.data.time.TimeSeriesCollection; 152 import org.jfree.data.xy.DefaultHighLowDataset; 153 import org.jfree.data.xy.IntervalXYDataset; 154 import org.jfree.data.xy.XYDataset; 155 import org.jfree.data.xy.XYZDataset; 156 157 158 163 public class JRFillChart extends JRFillElement implements JRChart 164 { 165 166 167 170 private static final Color TRANSPARENT_PAINT = new Color (0, 0, 0, 0); 171 172 175 protected byte chartType = 0; 176 177 180 protected JRFont titleFont = null; 181 protected JRFont subtitleFont = null; 182 protected JRFont legendFont = null; 183 184 187 protected JRGroup evaluationGroup = null; 188 189 protected JRFillChartDataset dataset = null; 190 protected JRChartPlot plot = null; 191 192 protected JRRenderable renderer = null; 193 private String anchorName = null; 194 private String hyperlinkReference = null; 195 private String hyperlinkAnchor = null; 196 private Integer hyperlinkPage = null; 197 private String hyperlinkTooltip; 198 private JRPrintHyperlinkParameters hyperlinkParameters; 199 200 protected String customizerClass; 201 protected JRChartCustomizer chartCustomizer; 202 203 206 protected JRFillChart( 207 JRBaseFiller filler, 208 JRChart chart, 209 JRFillObjectFactory factory 210 ) 211 { 212 super(filler, chart, factory); 213 214 215 chartType = chart.getChartType(); 216 217 switch(chartType) { 218 case CHART_TYPE_AREA: 219 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 220 plot = factory.getAreaPlot((JRAreaPlot) chart.getPlot()); 221 break; 222 case CHART_TYPE_BAR: 223 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 224 plot = factory.getBarPlot((JRBarPlot) chart.getPlot()); 225 break; 226 case CHART_TYPE_BAR3D: 227 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 228 plot = factory.getBar3DPlot((JRBar3DPlot) chart.getPlot()); 229 break; 230 case CHART_TYPE_BUBBLE: 231 dataset = (JRFillChartDataset) factory.getXyzDataset((JRXyzDataset) chart.getDataset()); 232 plot = factory.getBubblePlot((JRBubblePlot) chart.getPlot()); 233 break; 234 case CHART_TYPE_CANDLESTICK: 235 dataset = (JRFillChartDataset) factory.getHighLowDataset((JRHighLowDataset) chart.getDataset()); 236 plot = factory.getCandlestickPlot((JRCandlestickPlot) chart.getPlot()); 237 break; 238 case CHART_TYPE_HIGHLOW: 239 dataset = (JRFillChartDataset) factory.getHighLowDataset((JRHighLowDataset) chart.getDataset()); 240 plot = factory.getHighLowPlot((JRHighLowPlot) chart.getPlot()); 241 break; 242 case CHART_TYPE_LINE: 243 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 244 plot = factory.getLinePlot((JRLinePlot) chart.getPlot()); 245 break; 246 case CHART_TYPE_METER: 247 dataset = (JRFillChartDataset) factory.getValueDataset((JRValueDataset) chart.getDataset()); 248 plot = factory.getMeterPlot((JRMeterPlot) chart.getPlot()); 249 break; 250 case CHART_TYPE_MULTI_AXIS: 251 plot = factory.getMultiAxisPlot((JRMultiAxisPlot) chart.getPlot()); 252 dataset = ((JRFillMultiAxisPlot)plot).getMainDataset(); 253 break; 254 case CHART_TYPE_PIE: 255 dataset = (JRFillChartDataset) factory.getPieDataset((JRPieDataset) chart.getDataset()); 256 plot = factory.getPiePlot((JRPiePlot) chart.getPlot()); 257 break; 258 case CHART_TYPE_PIE3D: 259 dataset = (JRFillChartDataset) factory.getPieDataset((JRPieDataset) chart.getDataset()); 260 plot = factory.getPie3DPlot((JRPie3DPlot) chart.getPlot()); 261 break; 262 case CHART_TYPE_SCATTER: 263 dataset = (JRFillChartDataset) factory.getXyDataset((JRXyDataset) chart.getDataset()); 264 plot = factory.getScatterPlot((JRScatterPlot) chart.getPlot()); 265 break; 266 case CHART_TYPE_STACKEDBAR: 267 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 268 plot = factory.getBarPlot((JRBarPlot) chart.getPlot()); 269 break; 270 case CHART_TYPE_STACKEDBAR3D: 271 dataset = (JRFillChartDataset) factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 272 plot = factory.getBar3DPlot((JRBar3DPlot) chart.getPlot()); 273 break; 274 case CHART_TYPE_THERMOMETER: 275 dataset = (JRFillChartDataset) factory.getValueDataset((JRValueDataset) chart.getDataset()); 276 plot = factory.getThermometerPlot((JRThermometerPlot) chart.getPlot()); 277 break; 278 case CHART_TYPE_TIMESERIES: 279 dataset = (JRFillChartDataset) factory.getTimeSeriesDataset((JRTimeSeriesDataset)chart.getDataset()); 280 plot = factory.getTimeSeriesPlot((JRTimeSeriesPlot)chart.getPlot()); 281 break; 282 case CHART_TYPE_XYAREA: 283 dataset = (JRFillChartDataset) factory.getXyDataset((JRXyDataset) chart.getDataset()); 284 plot = factory.getAreaPlot((JRAreaPlot) chart.getPlot()); 285 break; 286 case CHART_TYPE_XYBAR: 287 switch (chart.getDataset().getDatasetType()){ 288 case JRChartDataset.TIMESERIES_DATASET: 289 dataset = (JRFillChartDataset) factory.getTimeSeriesDataset( (JRTimeSeriesDataset)chart.getDataset() ); 290 break; 291 case JRChartDataset.TIMEPERIOD_DATASET: 292 dataset = (JRFillChartDataset) factory.getTimePeriodDataset((JRTimePeriodDataset) chart.getDataset() ); 293 break; 294 case JRChartDataset.XY_DATASET: 295 dataset = (JRFillChartDataset) factory.getXyDataset( (JRXyDataset)chart.getDataset() ); 296 break; 297 } 298 299 plot = factory.getBarPlot((JRBarPlot) chart.getPlot()); 300 break; 301 case CHART_TYPE_XYLINE: 302 dataset = (JRFillChartDataset) factory.getXyDataset((JRXyDataset) chart.getDataset()); 303 plot = factory.getLinePlot((JRLinePlot) chart.getPlot()); 304 break; 305 default: 306 throw new JRRuntimeException("Chart type not supported."); 307 } 308 309 if (chart.getTitleFont() != null) 310 titleFont = factory.getFont(chart.getTitleFont()); 311 312 if (chart.getSubtitleFont() != null) 313 subtitleFont = factory.getFont(chart.getSubtitleFont()); 314 315 if (chart.getLegendFont() != null) 316 legendFont = factory.getFont(chart.getLegendFont()); 317 318 evaluationGroup = factory.getGroup(chart.getEvaluationGroup()); 319 320 customizerClass = chart.getCustomizerClass(); 321 if (customizerClass != null && customizerClass.length() > 0) { 322 try { 323 Class myClass = JRClassLoader.loadClassForName(customizerClass); 324 chartCustomizer = (JRChartCustomizer) myClass.newInstance(); 325 } catch (Exception e) { 326 throw new JRRuntimeException("Could not create chart customizer instance.", e); 327 } 328 329 if (chartCustomizer instanceof JRAbstractChartCustomizer) 330 { 331 ((JRAbstractChartCustomizer) chartCustomizer).init(filler, this); 332 } 333 } 334 } 335 336 337 340 public byte getMode() 341 { 342 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 343 } 344 345 348 public boolean isShowLegend() 349 { 350 return ((JRChart)parent).isShowLegend(); 351 } 352 353 356 public void setShowLegend(boolean isShowLegend) 357 { 358 } 359 360 363 public byte getEvaluationTime() 364 { 365 return ((JRChart)parent).getEvaluationTime(); 366 } 367 368 371 public JRGroup getEvaluationGroup() 372 { 373 return evaluationGroup; 374 } 375 376 379 public JRBox getBox() 380 { 381 return (JRBox)parent; 382 } 383 384 387 public JRFont getTitleFont() 388 { 389 return titleFont; 390 } 391 392 395 public byte getTitlePosition() 396 { 397 return ((JRChart)parent).getTitlePosition(); 398 } 399 400 403 public void setTitlePosition(byte titlePosition) 404 { 405 } 406 407 410 public Color getTitleColor() 411 { 412 return ((JRChart)parent).getTitleColor(); 413 } 414 415 418 public void setTitleColor(Color titleColor) 419 { 420 } 421 422 425 public JRFont getSubtitleFont() 426 { 427 return subtitleFont; 428 } 429 430 433 public Color getSubtitleColor() 434 { 435 return ((JRChart)parent).getSubtitleColor(); 436 } 437 438 441 public void setSubtitleColor(Color subtitleColor) 442 { 443 } 444 445 450 public Color getLegendColor() 451 { 452 return ((JRChart)parent).getLegendColor(); 453 } 454 455 460 public void setLegendColor(Color legendColor) 461 { 462 } 463 464 469 public Color getLegendBackgroundColor() 470 { 471 return ((JRChart)parent).getLegendBackgroundColor(); 472 } 473 474 479 public void setLegendBackgroundColor(Color legendBackgroundColor) 480 { 481 } 482 483 488 public JRFont getLegendFont() 489 { 490 return legendFont; 491 } 492 493 496 public JRExpression getTitleExpression() 497 { 498 return ((JRChart)parent).getTitleExpression(); 499 } 500 501 504 public JRExpression getSubtitleExpression() 505 { 506 return ((JRChart)parent).getSubtitleExpression(); 507 } 508 509 512 public byte getHyperlinkType() 513 { 514 return ((JRChart)parent).getHyperlinkType(); 515 } 516 517 520 public byte getHyperlinkTarget() 521 { 522 return ((JRChart)parent).getHyperlinkTarget(); 523 } 524 525 528 public JRExpression getAnchorNameExpression() 529 { 530 return ((JRChart)parent).getAnchorNameExpression(); 531 } 532 533 536 public JRExpression getHyperlinkReferenceExpression() 537 { 538 return ((JRChart)parent).getHyperlinkReferenceExpression(); 539 } 540 541 544 public JRExpression getHyperlinkAnchorExpression() 545 { 546 return ((JRChart)parent).getHyperlinkAnchorExpression(); 547 } 548 549 552 public JRExpression getHyperlinkPageExpression() 553 { 554 return ((JRChart)parent).getHyperlinkPageExpression(); 555 } 556 557 558 561 public JRChartDataset getDataset() 562 { 563 return dataset; 564 } 565 566 569 public void setDataset(JRFillChartDataset dataset) 570 { 571 this.dataset = dataset; 572 } 573 574 577 public JRChartPlot getPlot() 578 { 579 return plot; 580 } 581 582 585 protected JRRenderable getRenderer() 586 { 587 return renderer; 588 } 589 590 593 protected String getAnchorName() 594 { 595 return anchorName; 596 } 597 598 601 protected String getHyperlinkReference() 602 { 603 return hyperlinkReference; 604 } 605 606 609 protected String getHyperlinkAnchor() 610 { 611 return hyperlinkAnchor; 612 } 613 614 617 protected Integer getHyperlinkPage() 618 { 619 return hyperlinkPage; 620 } 621 622 protected String getHyperlinkTooltip() 623 { 624 return hyperlinkTooltip; 625 } 626 627 628 631 protected JRTemplateImage getJRTemplateImage() 632 { 633 JRStyle style = getStyle(); 634 JRTemplateImage template = (JRTemplateImage) getTemplate(style); 635 if (template == null) 636 { 637 template = new JRTemplateImage(filler.getJasperPrint().getDefaultStyleProvider(), this); 638 registerTemplate(style, template); 639 } 640 return template; 641 } 642 643 644 647 protected void rewind() 648 { 649 } 650 651 652 655 protected void evaluate(byte evaluation) throws JRException 656 { 657 reset(); 658 659 evaluatePrintWhenExpression(evaluation); 660 661 if ( 662 (isPrintWhenExpressionNull() || 663 (!isPrintWhenExpressionNull() && 664 isPrintWhenTrue())) 665 ) 666 { 667 if (getEvaluationTime() == JRExpression.EVALUATION_TIME_NOW) 668 { 669 evaluateImage(evaluation); 670 } 671 } 672 } 673 674 675 678 protected JFreeChartRenderer evaluateImage(byte evaluation) throws JRException 679 { 680 evaluateDatasetRun(evaluation); 681 682 JFreeChartRenderer chartRenderer; 683 switch(chartType) { 684 case CHART_TYPE_AREA: 685 chartRenderer = evaluateAreaImage(evaluation); 686 break; 687 case CHART_TYPE_BAR: 688 chartRenderer = evaluateBarImage(evaluation); 689 break; 690 case CHART_TYPE_BAR3D: 691 chartRenderer = evaluateBar3DImage(evaluation); 692 break; 693 case CHART_TYPE_BUBBLE: 694 chartRenderer = evaluateBubbleImage(evaluation); 695 break; 696 case CHART_TYPE_CANDLESTICK: 697 chartRenderer = evaluateCandlestickImage(evaluation); 698 break; 699 case CHART_TYPE_HIGHLOW: 700 chartRenderer = evaluateHighLowImage(evaluation); 701 break; 702 case CHART_TYPE_LINE: 703 chartRenderer = evaluateLineImage(evaluation); 704 break; 705 case CHART_TYPE_METER: 706 chartRenderer = evaluateMeterImage(evaluation); 707 break; 708 case CHART_TYPE_MULTI_AXIS: 709 chartRenderer = evaluateMultiAxisImage(evaluation); 710 break; 711 case CHART_TYPE_PIE: 712 chartRenderer = evaluatePieImage(evaluation); 713 break; 714 case CHART_TYPE_PIE3D: 715 chartRenderer = evaluatePie3DImage(evaluation); 716 break; 717 case CHART_TYPE_SCATTER: 718 chartRenderer = evaluateScatterImage(evaluation); 719 break; 720 case CHART_TYPE_STACKEDBAR: 721 chartRenderer = evaluateStackedBarImage(evaluation); 722 break; 723 case CHART_TYPE_STACKEDBAR3D: 724 chartRenderer = evaluateStackedBar3DImage(evaluation); 725 break; 726 case CHART_TYPE_THERMOMETER: 727 chartRenderer = evaluateThermometerImage(evaluation); 728 break; 729 case CHART_TYPE_TIMESERIES: 730 chartRenderer = evaluateTimeSeriesImage( evaluation ); 731 break; 732 case CHART_TYPE_XYAREA: 733 chartRenderer = evaluateXyAreaImage(evaluation); 734 break; 735 case CHART_TYPE_XYBAR: 736 chartRenderer = evaluateXYBarImage(evaluation); 737 break; 738 case CHART_TYPE_XYLINE: 739 chartRenderer = evaluateXyLineImage(evaluation); 740 break; 741 default: 742 throw new JRRuntimeException("Chart type " + getChartType() + " not supported."); 743 } 744 745 if (chartCustomizer != null) 746 { 747 chartCustomizer.customize(chartRenderer.getChart(), this); 748 } 749 750 renderer = chartRenderer; 751 752 anchorName = (String ) evaluateExpression(getAnchorNameExpression(), evaluation); 753 hyperlinkReference = (String ) evaluateExpression(getHyperlinkReferenceExpression(), evaluation); 754 hyperlinkAnchor = (String ) evaluateExpression(getHyperlinkAnchorExpression(), evaluation); 755 hyperlinkPage = (Integer ) evaluateExpression(getHyperlinkPageExpression(), evaluation); 756 hyperlinkTooltip = (String ) evaluateExpression(getHyperlinkTooltipExpression(), evaluation); 757 hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(this, expressionEvaluator, evaluation); 758 759 return chartRenderer; 760 } 761 762 763 766 protected boolean prepare( 767 int availableStretchHeight, 768 boolean isOverflow 769 ) 770 { 771 boolean willOverflow = false; 772 773 if ( 774 isPrintWhenExpressionNull() || 775 ( !isPrintWhenExpressionNull() && 776 isPrintWhenTrue() ) 777 ) 778 { 779 setToPrint(true); 780 } 781 else 782 { 783 setToPrint(false); 784 } 785 786 if (!isToPrint()) 787 { 788 return willOverflow; 789 } 790 791 boolean isToPrint = true; 792 boolean isReprinted = false; 793 794 if (getEvaluationTime() == JRExpression.EVALUATION_TIME_NOW) 795 { 796 if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows()) 797 { 798 isToPrint = false; 799 } 800 801 if ( 802 isToPrint && 803 availableStretchHeight < getRelativeY() - getY() - getBandBottomY() 804 ) 805 { 806 isToPrint = false; 807 willOverflow = true; 808 } 809 810 if ( 811 isToPrint && 812 isOverflow && 813 (isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues()))) 815 ) 816 { 817 isReprinted = true; 818 } 819 820 if ( 821 isToPrint && 822 isRemoveLineWhenBlank() && 823 getRenderer() == null 824 ) 825 { 826 isToPrint = false; 827 } 828 } 829 else 830 { 831 if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows()) 832 { 833 isToPrint = false; 834 } 835 836 if ( 837 isToPrint && 838 availableStretchHeight < getRelativeY() - getY() - getBandBottomY() 839 ) 840 { 841 isToPrint = false; 842 willOverflow = true; 843 } 844 845 if ( 846 isToPrint && 847 isOverflow && 848 (isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues()))) 850 ) 851 { 852 isReprinted = true; 853 } 854 } 855 856 setToPrint(isToPrint); 857 setReprinted(isReprinted); 858 859 return willOverflow; 860 } 861 862 863 866 protected JRPrintElement fill() 867 { 868 JRTemplatePrintImage printImage = new JRTemplatePrintImage(getJRTemplateImage()); 869 870 printImage.setX(getX()); 871 printImage.setY(getRelativeY()); 872 printImage.setWidth(getWidth()); 873 printImage.setHeight(getStretchHeight()); 874 875 byte evaluationType = getEvaluationTime(); 876 if (evaluationType == JRExpression.EVALUATION_TIME_NOW) 877 { 878 copy(printImage); 879 } 880 else 881 { 882 filler.addBoundElement(this, printImage, evaluationType, getEvaluationGroup(), band); 883 } 884 885 return printImage; 886 } 887 888 889 892 protected void copy(JRPrintImage printImage) 893 { 894 printImage.setRenderer(getRenderer()); 895 printImage.setAnchorName(getAnchorName()); 896 printImage.setHyperlinkReference(getHyperlinkReference()); 897 printImage.setHyperlinkAnchor(getHyperlinkAnchor()); 898 printImage.setHyperlinkPage(getHyperlinkPage()); 899 printImage.setHyperlinkTooltip(getHyperlinkTooltip()); 900 printImage.setBookmarkLevel(getBookmarkLevel()); 901 printImage.setHyperlinkParameters(hyperlinkParameters); 902 } 903 904 public byte getChartType() 905 { 906 return chartType; 907 } 908 909 910 public JRChild getCopy(JRAbstractObjectFactory factory) 911 { 912 return factory.getChart(this); 913 } 914 915 916 public void collectExpressions(JRExpressionCollector collector) 917 { 918 collector.collect(this); 919 } 920 921 922 926 public void writeXml(JRXmlWriter writer) 927 { 928 } 929 930 931 934 private void configureChart(JFreeChart chart, JRChartPlot jrPlot, byte evaluation) throws JRException 935 { 936 if (getMode() == JRElement.MODE_OPAQUE) 937 { 938 chart.setBackgroundPaint(getBackcolor()); 939 } 940 else 941 { 942 chart.setBackgroundPaint(TRANSPARENT_PAINT); 943 } 944 945 if (chart.getTitle() != null) 946 { 947 TextTitle title = chart.getTitle(); 948 title.setPaint(getTitleColor()); 949 950 JRFont font = getTitleFont(); 951 if (font != null) { 952 Map attributes = JRFontUtil.getAttributes(font); 953 title.setFont(new Font (attributes)); 954 } 955 956 } 957 958 String subtitleText = (String )evaluateExpression(getSubtitleExpression(), evaluation); 959 if (subtitleText != null) 960 { 961 TextTitle subtitle = new TextTitle(subtitleText); 962 subtitle.setPaint(getSubtitleColor()); 963 964 JRFont font = getSubtitleFont(); 965 if (font != null) { 966 Map attributes = JRFontUtil.getAttributes(font); 967 subtitle.setFont(new Font (attributes)); 968 } 969 970 chart.addSubtitle(subtitle); 971 } 972 973 if (getLegendColor() != null) 975 chart.getLegend().setItemPaint(getLegendColor()); 976 if (getLegendBackgroundColor() != null) 977 chart.getLegend().setBackgroundPaint(getLegendBackgroundColor()); 978 if (getLegendFont() != null) 979 { 980 Map attributes = JRFontUtil.getAttributes(getLegendFont()); 981 chart.getLegend().setItemFont(new Font (attributes)); 982 } 983 984 configurePlot(chart.getPlot(), jrPlot); 985 } 986 987 988 991 private void configurePlot(Plot p, JRChartPlot jrPlot) 992 { 993 p.setOutlinePaint(TRANSPARENT_PAINT); 994 995 if (getPlot().getBackcolor() == null) 996 { 997 p.setBackgroundPaint(TRANSPARENT_PAINT); 998 } 999 else 1000 { 1001 p.setBackgroundPaint(getPlot().getBackcolor()); 1002 } 1003 1004 p.setBackgroundAlpha(getPlot().getBackgroundAlpha()); 1005 p.setForegroundAlpha(getPlot().getForegroundAlpha()); 1006 1007 SortedSet seriesColors = getPlot().getSeriesColors(); 1008 if (p instanceof CategoryPlot) 1009 { 1010 CategoryAxis axis = ((CategoryPlot)p).getDomainAxis(); 1012 double labelRotation = getPlot().getLabelRotation(); 1013 if (labelRotation == 90) 1014 { 1015 axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); 1016 } 1017 else if (labelRotation == -90) { 1018 axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); 1019 } 1020 else if (labelRotation < 0) 1021 { 1022 axis.setCategoryLabelPositions( 1023 CategoryLabelPositions.createUpRotationLabelPositions( (-labelRotation / 180.0) * Math.PI)); 1024 } 1025 else if (labelRotation > 0) 1026 { 1027 axis.setCategoryLabelPositions( 1028 CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI)); 1029 } 1030 } 1031 1032 1033 if (seriesColors != null) 1035 { 1036 if (seriesColors.size() == 1) 1037 { 1038 Paint [] colors = new Paint [DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + 1]; 1041 colors[0] = ((JRSeriesColor)seriesColors.first()).getColor(); 1042 for (int i = 0; i < DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length; i++) 1043 { 1044 colors[i + 1] = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]; 1045 } 1046 1047 p.setDrawingSupplier(new DefaultDrawingSupplier(colors, 1048 DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, 1049 DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, 1050 DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, 1051 DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); 1052 } 1053 else if (seriesColors.size() > 1) 1054 { 1055 Color [] colors = new Color [seriesColors.size()]; 1058 JRSeriesColor[] colorSequence = new JRSeriesColor[seriesColors.size()]; 1059 seriesColors.toArray(colorSequence); 1060 for (int i = 0; i < colorSequence.length; i++) 1061 { 1062 colors[i] = colorSequence[i].getColor(); 1063 } 1064 1065 p.setDrawingSupplier(new DefaultDrawingSupplier(colors, 1066 DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, 1067 DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, 1068 DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, 1069 DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); 1070 } 1071 } 1072 } 1073 1074 1087 private void configureAxisSeriesColors(CategoryItemRenderer renderer, JRChartPlot jrPlot) 1088 { 1089 SortedSet seriesColors = jrPlot.getSeriesColors(); 1090 1091 if (seriesColors != null) 1092 { 1093 Iterator iter = seriesColors.iterator(); 1094 while (iter.hasNext()) 1095 { 1096 JRSeriesColor seriesColor = (JRSeriesColor)iter.next(); 1097 renderer.setSeriesPaint(seriesColor.getSeriesOrder(), seriesColor.getColor()); 1098 } 1099 } 1100 } 1101 1102 1115 private void configureAxisSeriesColors(XYItemRenderer renderer, JRChartPlot jrPlot) 1116 { 1117 SortedSet seriesColors = jrPlot.getSeriesColors(); 1118 1119 if (seriesColors != null) 1120 { 1121 Iterator iter = seriesColors.iterator(); 1122 while (iter.hasNext()) 1123 { 1124 JRSeriesColor seriesColor = (JRSeriesColor)iter.next(); 1125 renderer.setSeriesPaint(seriesColor.getSeriesOrder(), seriesColor.getColor()); 1126 } 1127 } 1128 } 1129 1130 1145 private void configureAxis(Axis axis, JRFont labelFont, Color labelColor, 1146 JRFont tickLabelFont, Color tickLabelColor, String tickLabelMask, 1147 Color lineColor) 1148 { 1149 if (labelFont != null) 1150 { 1151 Map attributes = JRFontUtil.getAttributes(labelFont); 1152 axis.setLabelFont(new Font (attributes)); 1153 } 1154 1155 if (tickLabelFont != null) 1156 { 1157 Map attributes = JRFontUtil.getAttributes(tickLabelFont); 1158 axis.setTickLabelFont(new Font (attributes)); 1159 } 1160 1161 if (labelColor != null) 1162 { 1163 axis.setLabelPaint(labelColor); 1164 } 1165 1166 if (tickLabelColor != null) 1167 { 1168 axis.setTickLabelPaint(tickLabelColor); 1169 } 1170 1171 if (lineColor != null) 1172 { 1173 axis.setAxisLinePaint(lineColor); 1174 axis.setTickMarkPaint(lineColor); 1175 } 1176 1177 if (tickLabelMask != null) 1178 { 1179 if (axis instanceof NumberAxis) 1180 { 1181 NumberFormat fmt = NumberFormat.getInstance(); 1182 if (fmt instanceof DecimalFormat ) 1183 ((DecimalFormat ) fmt).applyPattern(tickLabelMask); 1184 ((NumberAxis)axis).setNumberFormatOverride(fmt); 1185 } 1186 else if (axis instanceof DateAxis) 1187 { 1188 DateFormat fmt = null; 1189 if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT")) 1190 fmt = DateFormat.getDateInstance(DateFormat.SHORT); 1191 else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM")) 1192 fmt = DateFormat.getDateInstance(DateFormat.MEDIUM); 1193 else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG")) 1194 fmt = DateFormat.getDateInstance(DateFormat.LONG); 1195 else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL")) 1196 fmt = DateFormat.getDateInstance(DateFormat.FULL); 1197 else 1198 fmt = new SimpleDateFormat (tickLabelMask); 1199 1200 ((DateAxis)axis).setDateFormatOverride(fmt); 1201 } 1202 } 1204 } 1205 1208 protected JFreeChartRenderer evaluateAreaImage( byte evaluation ) throws JRException { 1209 JFreeChart chart = ChartFactory.createAreaChart( (String )evaluateExpression(getTitleExpression(), evaluation ), 1210 (String )evaluateExpression(((JRAreaPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation ), 1211 (String )evaluateExpression(((JRAreaPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1212 (CategoryDataset)dataset.getDataset(), 1213 getPlot().getOrientation(), 1214 isShowLegend(), 1215 true, 1216 false); 1217 1218 configureChart(chart, getPlot(), evaluation); 1219 JRFillAreaPlot areaPlot = (JRFillAreaPlot)getPlot(); 1220 1221 configureAxis(((CategoryPlot)chart.getPlot()).getDomainAxis(), areaPlot.getCategoryAxisLabelFont(), 1223 areaPlot.getCategoryAxisLabelColor(), areaPlot.getCategoryAxisTickLabelFont(), 1224 areaPlot.getCategoryAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(), 1225 areaPlot.getCategoryAxisLineColor()); 1226 1227 configureAxis(((CategoryPlot)chart.getPlot()).getRangeAxis(), areaPlot.getValueAxisLabelFont(), 1229 areaPlot.getValueAxisLabelColor(), areaPlot.getValueAxisTickLabelFont(), 1230 areaPlot.getValueAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(), 1231 areaPlot.getValueAxisLineColor()); 1232 1233 return getCategoryRenderer(chart); 1234 } 1235 1236 1237 protected JFreeChartRenderer evaluateBar3DImage( byte evaluation ) throws JRException { 1238 JFreeChart chart = 1239 ChartFactory.createBarChart3D( 1240 (String )evaluateExpression( getTitleExpression(), evaluation ), 1241 (String )evaluateExpression(((JRBar3DPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation ), 1242 (String )evaluateExpression(((JRBar3DPlot)getPlot()).getValueAxisLabelExpression(), evaluation ), 1243 (CategoryDataset)dataset.getDataset(), 1244 getPlot().getOrientation(), 1245 isShowLegend(), 1246 true, 1247 false ); 1248 1249 configureChart(chart, getPlot(), evaluation); 1250 1251 CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); 1252 JRFillBar3DPlot bar3DPlot = (JRFillBar3DPlot)getPlot(); 1253 1254 BarRenderer3D barRenderer3D = 1255 new BarRenderer3D( 1256 bar3DPlot.getXOffset(), 1257 bar3DPlot.getYOffset() 1258 ); 1259 categoryPlot.setRenderer(barRenderer3D); 1260 1261 barRenderer3D.setBaseItemLabelGenerator(((JRFillCategoryDataset)getDataset()).getLabelGenerator()); 1262 barRenderer3D.setItemLabelsVisible( bar3DPlot.isShowLabels() ); 1263 1264 configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(), 1266 bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(), 1267 bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), 1268 bar3DPlot.getCategoryAxisLineColor()); 1269 1270 configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(), 1272 bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(), 1273 bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), 1274 bar3DPlot.getValueAxisLineColor()); 1275 1276 return getCategoryRenderer(chart); 1277 } 1278 1279 1280 1283 protected JFreeChartRenderer evaluateBarImage(byte evaluation) throws JRException 1284 { 1285 CategoryDataset categoryDataset = (CategoryDataset)dataset.getDataset(); 1286 JFreeChart chart = 1287 ChartFactory.createBarChart( 1288 (String )evaluateExpression(getTitleExpression(), evaluation), 1289 (String )evaluateExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation), 1290 (String )evaluateExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1291 categoryDataset, 1292 getPlot().getOrientation(), 1293 isShowLegend(), 1294 true, 1295 false 1296 ); 1297 1298 configureChart(chart, getPlot(), evaluation); 1299 1300 CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); 1301 1303 JRFillBarPlot barPlot = (JRFillBarPlot)getPlot(); 1304 categoryPlot.getDomainAxis().setTickMarksVisible( 1305 barPlot.isShowTickMarks() 1306 ); 1307 categoryPlot.getDomainAxis().setTickLabelsVisible( 1308 barPlot.isShowTickLabels() 1309 ); 1310 configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), 1312 barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), 1313 barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), 1314 barPlot.getCategoryAxisLineColor()); 1315 1316 ((NumberAxis)categoryPlot.getRangeAxis()).setTickMarksVisible( 1317 barPlot.isShowTickMarks() 1318 ); 1319 ((NumberAxis)categoryPlot.getRangeAxis()).setTickLabelsVisible( 1320 barPlot.isShowTickLabels() 1321 ); 1322 configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), 1324 barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), 1325 barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), 1326 barPlot.getValueAxisLineColor()); 1327 1328 1329 CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer(); 1330 categoryRenderer.setBaseItemLabelGenerator(((JRFillCategoryDataset)getDataset()).getLabelGenerator()); 1331 categoryRenderer.setItemLabelsVisible( barPlot.isShowLabels() ); 1332 1333 return getCategoryRenderer(chart); 1334 1335 } 1336 1337 1338 protected JFreeChartRenderer evaluateBubbleImage( byte evaluation ) throws JRException { 1339 JFreeChart chart = ChartFactory.createBubbleChart( 1340 (String )evaluateExpression( getTitleExpression(), evaluation), 1341 (String )evaluateExpression(((JRBubblePlot)getPlot()).getXAxisLabelExpression(), evaluation ), 1342 (String )evaluateExpression(((JRBubblePlot)getPlot()).getYAxisLabelExpression(), evaluation ), 1343 (XYZDataset)dataset.getDataset(), 1344 getPlot().getOrientation(), 1345 isShowLegend(), 1346 true, 1347 false); 1348 1349 configureChart(chart, getPlot(), evaluation); 1350 1351 XYPlot xyPlot = (XYPlot)chart.getPlot(); 1352 JRBubblePlot bubblePlot = (JRBubblePlot)getPlot(); 1353 1354 XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer( bubblePlot.getScaleType() ); 1355 xyPlot.setRenderer( bubbleRenderer ); 1356 1357 configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(), 1359 bubblePlot.getXAxisLabelColor(), bubblePlot.getXAxisTickLabelFont(), 1360 bubblePlot.getXAxisTickLabelColor(), bubblePlot.getXAxisTickLabelMask(), 1361 bubblePlot.getXAxisLineColor()); 1362 1363 configureAxis(xyPlot.getRangeAxis(), bubblePlot.getYAxisLabelFont(), 1365 bubblePlot.getYAxisLabelColor(), bubblePlot.getYAxisTickLabelFont(), 1366 bubblePlot.getYAxisTickLabelColor(), bubblePlot.getYAxisTickLabelMask(), 1367 bubblePlot.getYAxisLineColor()); 1368 1369 return getXYZRenderer(chart); 1370 } 1371 1372 1373 1378 protected JFreeChartRenderer evaluateCandlestickImage(byte evaluation) throws JRException 1379 { 1380 JFreeChart chart = 1381 ChartFactory.createCandlestickChart( 1382 (String )evaluateExpression(getTitleExpression(), evaluation), 1383 (String )evaluateExpression(((JRCandlestickPlot)getPlot()).getTimeAxisLabelExpression(), evaluation), 1384 (String )evaluateExpression(((JRCandlestickPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1385 (DefaultHighLowDataset)dataset.getDataset(), 1386 isShowLegend() 1387 ); 1388 1389 configureChart(chart, getPlot(), evaluation); 1390 1391 XYPlot xyPlot = (XYPlot) chart.getPlot(); 1392 JRCandlestickPlot candlestickPlot = (JRCandlestickPlot)getPlot(); 1393 CandlestickRenderer candlestickRenderer = (CandlestickRenderer) xyPlot.getRenderer(); 1394 candlestickRenderer.setDrawVolume(candlestickPlot.isShowVolume()); 1395 1396 configureAxis(xyPlot.getDomainAxis(), candlestickPlot.getTimeAxisLabelFont(), 1398 candlestickPlot.getTimeAxisLabelColor(), candlestickPlot.getTimeAxisTickLabelFont(), 1399 candlestickPlot.getTimeAxisTickLabelColor(), candlestickPlot.getTimeAxisTickLabelMask(), 1400 candlestickPlot.getTimeAxisLineColor()); 1401 1402 configureAxis(xyPlot.getRangeAxis(), candlestickPlot.getValueAxisLabelFont(), 1404 candlestickPlot.getValueAxisLabelColor(), candlestickPlot.getValueAxisTickLabelFont(), 1405 candlestickPlot.getValueAxisTickLabelColor(), candlestickPlot.getValueAxisTickLabelMask(), 1406 candlestickPlot.getValueAxisLineColor()); 1407 1408 return getHighLowRenderer(chart); 1409 } 1410 1411 1412 1417 protected JFreeChartRenderer evaluateHighLowImage(byte evaluation) throws JRException 1418 { 1419 JFreeChart chart = 1420 ChartFactory.createHighLowChart( 1421 (String )evaluateExpression(getTitleExpression(), evaluation), 1422 (String )evaluateExpression(((JRHighLowPlot)getPlot()).getTimeAxisLabelExpression(), evaluation), 1423 (String )evaluateExpression(((JRHighLowPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1424 (DefaultHighLowDataset)dataset.getDataset(), 1425 isShowLegend() 1426 ); 1427 1428 configureChart(chart, getPlot(), evaluation); 1429 1430 XYPlot xyPlot = (XYPlot) chart.getPlot(); 1431 JRHighLowPlot highLowPlot = (JRHighLowPlot)getPlot(); 1432 HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); 1433 hlRenderer.setDrawOpenTicks(highLowPlot.isShowOpenTicks()); 1434 hlRenderer.setDrawCloseTicks(highLowPlot.isShowCloseTicks()); 1435 1436 configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), 1438 highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), 1439 highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), 1440 highLowPlot.getTimeAxisLineColor()); 1441 1442 configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), 1444 highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), 1445 highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), 1446 highLowPlot.getValueAxisLineColor()); 1447 1448 return getHighLowRenderer(chart); 1449 } 1450 1451 1452 protected JFreeChartRenderer evaluateLineImage( byte evaluation ) throws JRException { 1453 JFreeChart chart = ChartFactory.createLineChart( 1454 (String )evaluateExpression( getTitleExpression(), evaluation), 1455 (String )evaluateExpression( ((JRLinePlot)getPlot()).getCategoryAxisLabelExpression(), evaluation), 1456 (String )evaluateExpression(((JRLinePlot)getPlot()).getValueAxisLabelExpression(), evaluation ), 1457 (CategoryDataset)dataset.getDataset(), 1458 getPlot().getOrientation(), 1459 isShowLegend(), 1460 true, 1461 false); 1462 1463 configureChart(chart, getPlot(), evaluation); 1464 1465 CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); 1466 JRFillLinePlot linePlot = (JRFillLinePlot)getPlot(); 1467 1468 LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer)categoryPlot.getRenderer(); 1469 lineRenderer.setShapesVisible( linePlot.isShowShapes() ); lineRenderer.setLinesVisible( linePlot.isShowLines() ); 1471 1472 configureAxis(categoryPlot.getDomainAxis(), linePlot.getCategoryAxisLabelFont(), 1474 linePlot.getCategoryAxisLabelColor(), linePlot.getCategoryAxisTickLabelFont(), 1475 linePlot.getCategoryAxisTickLabelColor(), linePlot.getCategoryAxisTickLabelMask(), 1476 linePlot.getCategoryAxisLineColor()); 1477 1478 configureAxis(categoryPlot.getRangeAxis(), linePlot.getValueAxisLabelFont(), 1480 linePlot.getValueAxisLabelColor(), linePlot.getValueAxisTickLabelFont(), 1481 linePlot.getValueAxisTickLabelColor(), linePlot.getValueAxisTickLabelMask(), 1482 linePlot.getValueAxisLineColor()); 1483 1484 return getCategoryRenderer(chart); 1485 } 1486 1487 1488 1491 protected JFreeChartRenderer evaluatePie3DImage(byte evaluation) throws JRException 1492 { 1493 JFreeChart chart = 1494 ChartFactory.createPieChart3D( 1495 (String )evaluateExpression(getTitleExpression(), evaluation), 1496 (PieDataset)dataset.getDataset(), 1497 isShowLegend(), 1498 true, 1499 false 1500 ); 1501 1502 configureChart(chart, getPlot(), evaluation); 1503 1504 PiePlot3D piePlot3D = (PiePlot3D) chart.getPlot(); 1505 piePlot3D.setDepthFactor(((JRFillPie3DPlot)getPlot()).getDepthFactor()); 1509 1510 PieSectionLabelGenerator labelGenerator = ((JRFillPieDataset)getDataset()).getLabelGenerator(); 1511 if (labelGenerator != null) 1512 { 1513 piePlot3D.setLabelGenerator(labelGenerator); 1514 } 1515 1516 return getPieRenderer(chart); 1517 } 1518 1519 1520 1523 protected JFreeChartRenderer evaluatePieImage(byte evaluation) throws JRException 1524 { 1525 JFreeChart chart = 1526 ChartFactory.createPieChart( 1527 (String )evaluateExpression(getTitleExpression(), evaluation), 1528 (PieDataset)dataset.getDataset(), 1529 isShowLegend(), 1530 true, 1531 false 1532 ); 1533 1534 configureChart(chart, getPlot(), evaluation); 1535 1536 PiePlot piePlot = (PiePlot)chart.getPlot(); 1537 1541 PieSectionLabelGenerator labelGenerator = ((JRFillPieDataset)getDataset()).getLabelGenerator(); 1542 if (labelGenerator != null) 1543 { 1544 piePlot.setLabelGenerator(labelGenerator); 1545 } 1546 1547 return getPieRenderer(chart); 1548 } 1549 1550 1551 protected JFreeChartRenderer evaluateScatterImage( byte evaluation ) throws JRException { 1552 JFreeChart chart = ChartFactory.createScatterPlot( 1553 (String )evaluateExpression( getTitleExpression(), evaluation), 1554 (String )evaluateExpression( ((JRScatterPlot)getPlot()).getXAxisLabelExpression(), evaluation), 1555 (String )evaluateExpression(((JRScatterPlot)getPlot()).getYAxisLabelExpression(), evaluation ), 1556 (XYDataset)dataset.getDataset(), 1557 getPlot().getOrientation(), 1558 isShowLegend(), 1559 true, 1560 false); 1561 1562 configureChart(chart, getPlot(), evaluation); 1563 XYLineAndShapeRenderer plotRenderer = (XYLineAndShapeRenderer) ((XYPlot)chart.getPlot()).getRenderer(); 1564 1565 JRScatterPlot scatterPlot = (JRScatterPlot) getPlot(); 1566 plotRenderer.setLinesVisible(scatterPlot.isShowLines()); 1567 plotRenderer.setShapesVisible(scatterPlot.isShowShapes()); 1568 1569 configureAxis(chart.getXYPlot().getDomainAxis(), scatterPlot.getXAxisLabelFont(), 1571 scatterPlot.getXAxisLabelColor(), scatterPlot.getXAxisTickLabelFont(), 1572 scatterPlot.getXAxisTickLabelColor(), scatterPlot.getXAxisTickLabelMask(), 1573 scatterPlot.getXAxisLineColor()); 1574 1575 configureAxis(chart.getXYPlot().getRangeAxis(), scatterPlot.getYAxisLabelFont(), 1577 scatterPlot.getYAxisLabelColor(), scatterPlot.getYAxisTickLabelFont(), 1578 scatterPlot.getYAxisTickLabelColor(), scatterPlot.getYAxisTickLabelMask(), 1579 scatterPlot.getYAxisLineColor()); 1580 1581 return getXYRenderer(chart); 1582 } 1583 1584 1585 1588 protected JFreeChartRenderer evaluateStackedBar3DImage(byte evaluation) throws JRException 1589 { 1590 JFreeChart chart = 1591 ChartFactory.createStackedBarChart3D( 1592 (String )evaluateExpression(getTitleExpression(), evaluation), 1593 (String )evaluateExpression(((JRBar3DPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation), 1594 (String )evaluateExpression(((JRBar3DPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1595 (CategoryDataset)dataset.getDataset(), 1596 getPlot().getOrientation(), 1597 isShowLegend(), 1598 true, 1599 false 1600 ); 1601 1602 configureChart(chart, getPlot(), evaluation); 1603 1604 CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); 1605 JRFillBar3DPlot bar3DPlot = (JRFillBar3DPlot)getPlot(); 1606 1607 StackedBarRenderer3D stackedBarRenderer3D = 1608 new StackedBarRenderer3D( 1609 bar3DPlot.getXOffset(), 1610 bar3DPlot.getYOffset() 1611 ); 1612 categoryPlot.setRenderer(stackedBarRenderer3D); 1613 1614 stackedBarRenderer3D.setBaseItemLabelGenerator(((JRFillCategoryDataset)getDataset()).getLabelGenerator()); 1615 stackedBarRenderer3D.setItemLabelsVisible( bar3DPlot.isShowLabels() ); 1616 1617 configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(), 1619 bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(), 1620 bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), 1621 bar3DPlot.getCategoryAxisLineColor()); 1622 1623 configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(), 1625 bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(), 1626 bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), 1627 bar3DPlot.getValueAxisLineColor()); 1628 1629 return getCategoryRenderer(chart); 1630 } 1631 1632 1633 1636 protected JFreeChartRenderer evaluateStackedBarImage(byte evaluation) throws JRException 1637 { 1638 JFreeChart chart = 1639 ChartFactory.createStackedBarChart( 1640 (String )evaluateExpression(getTitleExpression(), evaluation), 1641 (String )evaluateExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation), 1642 (String )evaluateExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1643 (CategoryDataset)dataset.getDataset(), 1644 getPlot().getOrientation(), 1645 isShowLegend(), 1646 true, 1647 false 1648 ); 1649 1650 configureChart(chart, getPlot(), evaluation); 1651 1652 CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); 1653 JRFillBarPlot barPlot = (JRFillBarPlot)getPlot(); 1654 1656 categoryPlot.getDomainAxis().setTickMarksVisible( 1657 barPlot.isShowTickMarks() 1658 ); 1659 categoryPlot.getDomainAxis().setTickLabelsVisible( 1660 barPlot.isShowTickLabels() 1661 ); 1662 ((NumberAxis)categoryPlot.getRangeAxis()).setTickMarksVisible( 1663 barPlot.isShowTickMarks() 1664 ); 1665 ((NumberAxis)categoryPlot.getRangeAxis()).setTickLabelsVisible( 1666 barPlot.isShowTickLabels() 1667 ); 1668 1669 CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer(); 1670 categoryRenderer.setBaseItemLabelGenerator(((JRFillCategoryDataset)getDataset()).getLabelGenerator()); 1671 categoryRenderer.setItemLabelsVisible( ((JRFillBarPlot)getPlot()).isShowLabels() ); 1672 1673 configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), 1675 barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), 1676 barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), 1677 barPlot.getCategoryAxisLineColor()); 1678 1679 configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), 1681 barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), 1682 barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), 1683 barPlot.getValueAxisLineColor()); 1684 1685 return getCategoryRenderer(chart); 1686 } 1687 1688 1689 protected JFreeChartRenderer evaluateXyAreaImage( byte evaluation ) throws JRException { 1690 JFreeChart chart = ChartFactory.createXYAreaChart( 1691 (String )evaluateExpression(getTitleExpression(), evaluation ), 1692 (String )evaluateExpression(((JRAreaPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation ), 1693 (String )evaluateExpression(((JRAreaPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1694 (XYDataset)dataset.getDataset(), 1695 getPlot().getOrientation(), 1696 isShowLegend(), 1697 true, 1698 false 1699 ); 1700 1701 configureChart(chart, getPlot(), evaluation); 1702 JRAreaPlot areaPlot = (JRAreaPlot)getPlot(); 1703 1704 configureAxis(chart.getXYPlot().getDomainAxis(), areaPlot.getCategoryAxisLabelFont(), 1706 areaPlot.getCategoryAxisLabelColor(), areaPlot.getCategoryAxisTickLabelFont(), 1707 areaPlot.getCategoryAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(), 1708 areaPlot.getCategoryAxisLineColor()); 1709 1710 configureAxis(chart.getXYPlot().getRangeAxis(), areaPlot.getValueAxisLabelFont(), 1712 areaPlot.getValueAxisLabelColor(), areaPlot.getValueAxisTickLabelFont(), 1713 areaPlot.getValueAxisTickLabelColor(), areaPlot.getValueAxisTickLabelMask(), 1714 areaPlot.getValueAxisLineColor()); 1715 return getXYRenderer(chart); 1716 } 1717 1718 1719 1722 protected JFreeChartRenderer evaluateXYBarImage(byte evaluation) throws JRException 1723 { 1724 IntervalXYDataset tmpDataset = (IntervalXYDataset)dataset.getDataset(); 1725 1726 boolean isDate = true; 1727 if( dataset.getDatasetType() == JRChartDataset.XY_DATASET ){ 1728 isDate = false; 1729 } 1730 1731 JFreeChart chart = 1732 ChartFactory.createXYBarChart( 1733 (String )evaluateExpression(getTitleExpression(), evaluation), 1734 (String )evaluateExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression(), evaluation), 1735 isDate, 1736 (String )evaluateExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression(), evaluation), 1737 tmpDataset, 1738 getPlot().getOrientation(), 1739 isShowLegend(), 1740 true, 1741 false 1742 ); 1743 1744 configureChart(chart, getPlot(), evaluation); 1745 1746 XYPlot xyPlot = (XYPlot)chart.getPlot(); 1747 1761 1762 XYItemRenderer itemRenderer = xyPlot.getRenderer(); 1763 if( getDataset().getDatasetType() == JRChartDataset.TIMESERIES_DATASET ) { 1764 itemRenderer.setBaseItemLabelGenerator( ((JRFillTimeSeriesDataset)getDataset()).getLabelGenerator() ); 1765 } 1766 else if( getDataset().getDatasetType() == JRChartDataset.TIMEPERIOD_DATASET ){ 1767 itemRenderer.setBaseItemLabelGenerator( ((JRFillTimePeriodDataset)getDataset()).getLabelGenerator() ); 1768 } 1769 else if( getDataset().getDatasetType() == JRChartDataset.XY_DATASET ) { 1770 itemRenderer.setBaseItemLabelGenerator( ((JRFillXyDataset)getDataset()).getLabelGenerator() ); 1771 } 1772 1773 JRFillBarPlot barPlot = (JRFillBarPlot)getPlot(); 1774 1775 itemRenderer.setBaseItemLabelsVisible( barPlot.isShowLabels() ); 1776 1777 configureAxis(xyPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), 1779 barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), 1780 barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), 1781 barPlot.getCategoryAxisLineColor()); 1782 1783 configureAxis(xyPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), 1785 barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), 1786 barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), 1787 barPlot.getValueAxisLineColor()); 1788 1789 return getXYBarRenderer(chart); 1790 } 1791 1792 1793 protected JFreeChartRenderer evaluateXyLineImage( byte evaluation ) throws JRException { 1794 JRLinePlot linePlot = (JRLinePlot) getPlot(); 1795 1796 JFreeChart chart = ChartFactory.createXYLineChart( 1797 (String )evaluateExpression( getTitleExpression(), evaluation), 1798 (String )evaluateExpression(linePlot.getCategoryAxisLabelExpression(), evaluation), 1799 (String )evaluateExpression(linePlot.getValueAxisLabelExpression(), evaluation ), 1800 (XYDataset)dataset.getDataset(), 1801 linePlot.getOrientation(), 1802 isShowLegend(), 1803 true, 1804 false); 1805 1806 configureChart(chart, getPlot(), evaluation); 1807 1808 configureAxis(chart.getXYPlot().getDomainAxis(), linePlot.getCategoryAxisLabelFont(), 1810 linePlot.getCategoryAxisLabelColor(), linePlot.getCategoryAxisTickLabelFont(), 1811 linePlot.getCategoryAxisTickLabelColor(), linePlot.getCategoryAxisTickLabelMask(), 1812 linePlot.getCategoryAxisLineColor()); 1813 1814 configureAxis(chart.getXYPlot().getRangeAxis(), linePlot.getValueAxisLabelFont(), 1816 linePlot.getValueAxisLabelColor(), linePlot.getValueAxisTickLabelFont(), 1817 linePlot.getValueAxisTickLabelColor(), linePlot.getValueAxisTickLabelMask(), 1818 linePlot.getValueAxisLineColor()); 1819 1820 XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); 1821 lineRenderer.setShapesVisible(linePlot.isShowShapes()); 1822 lineRenderer.setLinesVisible(linePlot.isShowLines()); 1823 1824 return getXYRenderer(chart); 1825 } 1826 1827 protected JFreeChartRenderer evaluateTimeSeriesImage( byte evaluation ) throws JRException { 1828 1829 1830 String timeAxisLabel = (String )evaluateExpression( ((JRTimeSeriesPlot)getPlot()).getTimeAxisLabelExpression(), evaluation ); 1831 String valueAxisLabel = (String )evaluateExpression( ((JRTimeSeriesPlot)getPlot()).getValueAxisLabelExpression(), evaluation ); 1832 1833 JFreeChart chart = ChartFactory.createTimeSeriesChart( 1834 (String )evaluateExpression( getTitleExpression(), evaluation ), 1835 timeAxisLabel, 1836 valueAxisLabel, 1837 (TimeSeriesCollection)dataset.getDataset(), 1838 isShowLegend(), 1839 true, 1840 false ); 1841 1842 configureChart(chart, getPlot(), evaluation); 1843 1844 XYPlot xyPlot = (XYPlot)chart.getPlot(); 1845 JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot)getPlot(); 1846 1847 XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer)xyPlot.getRenderer(); 1848 lineRenderer.setLinesVisible(((JRTimeSeriesPlot)getPlot()).isShowLines() ); 1849 lineRenderer.setShapesVisible(((JRTimeSeriesPlot)getPlot()).isShowShapes() ); 1850 1851 configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(), 1853 timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(), 1854 timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(), 1855 timeSeriesPlot.getTimeAxisLineColor()); 1856 1857 configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(), 1859 timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(), 1860 timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(), 1861 timeSeriesPlot.getValueAxisLineColor()); 1862 1863 return getTimeSeriesRenderer(chart); 1864 1865 } 1866 1867 1868 1877 protected Range convertRange(JRDataRange dataRange, byte evaluation) throws JRException 1878 { 1879 if (dataRange == null) 1880 return null; 1881 1882 Number low = (Number )evaluateExpression(dataRange.getLowExpression(), evaluation); 1883 Number high = (Number )evaluateExpression(dataRange.getHighExpression(), evaluation); 1884 return new Range( low != null ? low.doubleValue() : 0.0, 1885 high != null ? high.doubleValue() : 100.0); 1886 } 1887 1888 1896 protected MeterInterval convertInterval(JRMeterInterval interval, byte evaluation) throws JRException 1897 { 1898 String label = interval.getLabel(); 1899 if (label == null) 1900 label = ""; 1901 1902 Range range = convertRange(interval.getDataRange(), evaluation); 1903 1904 Color color = interval.getBackgroundColor(); 1905 float[] components = color.getRGBColorComponents(null); 1906 1907 Color alphaColor = new Color (components[0], components[1], components[2], (float)interval.getAlpha()); 1908 1909 return new MeterInterval(label, range, alphaColor, null, alphaColor); 1910 } 1911 1912 1919 protected JFreeChartRenderer evaluateMeterImage( byte evaluation ) throws JRException { 1920 1921 JRFillMeterPlot jrPlot = (JRFillMeterPlot)getPlot(); 1922 1923 MeterPlot chartPlot = new MeterPlot((ValueDataset)dataset.getDataset()); 1925 1926 int shape = jrPlot.getShape(); 1928 if (shape == JRMeterPlot.SHAPE_CHORD) 1929 chartPlot.setDialShape(DialShape.CHORD); 1930 else if (shape == JRMeterPlot.SHAPE_CIRCLE) 1931 chartPlot.setDialShape(DialShape.CIRCLE); 1932 else 1933 chartPlot.setDialShape(DialShape.PIE); 1934 1935 chartPlot.setRange(convertRange(jrPlot.getDataRange(), evaluation)); 1937 1938 chartPlot.setMeterAngle(jrPlot.getMeterAngle()); 1940 1941 String units = jrPlot.getUnits(); 1944 if (units != null && units.length() > 0) 1945 chartPlot.setUnits(units); 1946 1947 chartPlot.setTickSize(jrPlot.getTickInterval()); 1950 1951 Color color = jrPlot.getMeterBackgroundColor(); 1953 if (color != null) 1954 chartPlot.setDialBackgroundPaint(color); 1955 1956 color = jrPlot.getNeedleColor(); 1957 if (color != null) 1958 chartPlot.setNeedlePaint(color); 1959 1960 JRValueDisplay display = jrPlot.getValueDisplay(); 1962 if (display != null) 1963 { 1964 if (display.getColor() != null) 1965 { 1966 chartPlot.setValuePaint(display.getColor()); 1967 } 1968 if (display.getMask() != null) 1969 { 1970 } 1973 if (display.getFont() != null) 1974 { 1975 Map attributes = JRFontUtil.getAttributes(display.getFont()); 1976 chartPlot.setValueFont(new Font (attributes)); 1977 } 1978 } 1979 1980 color = jrPlot.getTickColor(); 1981 if (color != null) 1982 chartPlot.setTickPaint(color); 1983 1984 List intervals = jrPlot.getIntervals(); 1986 if (intervals != null) 1987 { 1988 Iterator iter = intervals.iterator(); 1989 while (iter.hasNext()) 1990 { 1991 JRMeterInterval interval = (JRMeterInterval)iter.next(); 1992 chartPlot.addInterval(convertInterval(interval, evaluation)); 1993 } 1994 } 1995 1996 JFreeChart chart = new JFreeChart((String )evaluateExpression( getTitleExpression(), evaluation ), 1998 null, chartPlot, isShowLegend()); 1999 2000 configureChart(chart, getPlot(), evaluation); 2002 2003 return new JFreeChartRenderer(chart); 2005 2006 } 2007 2008 2017 protected JFreeChartRenderer evaluateThermometerImage( byte evaluation ) throws JRException { 2018 2019 JRFillThermometerPlot jrPlot = (JRFillThermometerPlot)getPlot(); 2020 2021 ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset)dataset.getDataset()); 2023 2024 Range range = convertRange(jrPlot.getDataRange(), evaluation); 2025 2026 chartPlot.setLowerBound(range.getLowerBound()); 2028 chartPlot.setUpperBound(range.getUpperBound()); 2029 2030 chartPlot.setShowValueLines(jrPlot.isShowValueLines()); 2031 2032 chartPlot.setUnits(ThermometerPlot.UNITS_NONE); 2034 2035 Color color = jrPlot.getMercuryColor(); 2038 if (color != null) 2039 { 2040 chartPlot.setMercuryPaint(color); 2041 } 2042 2043 JRValueDisplay display = jrPlot.getValueDisplay(); 2045 if (display != null) 2046 { 2047 if (display.getColor() != null) 2048 { 2049 chartPlot.setValuePaint(display.getColor()); 2050 } 2051 if (display.getMask() != null) 2052 { 2053 chartPlot.setValueFormat(new DecimalFormat (display.getMask())); 2054 } 2055 if (display.getFont() != null) 2056 { 2057 Map attributes = JRFontUtil.getAttributes(display.getFont()); 2058 chartPlot.setValueFont(new Font (attributes)); 2059 } 2060 } 2061 2062 switch (jrPlot.getValueLocation()) 2064 { 2065 case JRThermometerPlot.LOCATION_NONE: 2066 chartPlot.setValueLocation(ThermometerPlot.NONE); 2067 break; 2068 case JRThermometerPlot.LOCATION_LEFT: 2069 chartPlot.setValueLocation(ThermometerPlot.LEFT); 2070 break; 2071 case JRThermometerPlot.LOCATION_RIGHT: 2072 chartPlot.setValueLocation(ThermometerPlot.RIGHT); 2073 break; 2074 case JRThermometerPlot.LOCATION_BULB: 2075 default: 2076 chartPlot.setValueLocation(ThermometerPlot.BULB); 2077 break; 2078 } 2079 2080 range = convertRange(jrPlot.getLowRange(), evaluation); 2082 if (range != null) 2083 { 2084 chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound()); 2085 } 2086 2087 range = convertRange(jrPlot.getMediumRange(), evaluation); 2088 if (range != null) 2089 { 2090 chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound()); 2091 } 2092 2093 range = convertRange(jrPlot.getHighRange(), evaluation); 2094 if (range != null) 2095 { 2096 chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound()); 2097 } 2098 2099 JFreeChart chart = new JFreeChart(chartPlot); 2101 2102 configureChart(chart, getPlot(), evaluation); 2104 2105 return new JFreeChartRenderer(chart); 2108 2109 } 2110 2111 2130 protected JFreeChartRenderer evaluateMultiAxisImage(byte evaluation) throws JRException 2131 { 2132 JFreeChart mainChart = null; 2137 Plot mainPlot = null; 2138 2139 JRFillMultiAxisPlot jrPlot = (JRFillMultiAxisPlot)getPlot(); 2140 2141 Iterator iter = jrPlot.getAxes().iterator(); 2143 if (iter.hasNext()) 2144 { 2145 JRFillChartAxis axis = (JRFillChartAxis)iter.next(); 2146 JRFillChart fillChart = axis.getFillChart(); 2147 mainChart = fillChart.evaluateImage(evaluation).getChart(); 2148 configureChart(mainChart, getPlot(), evaluation); 2151 mainPlot = mainChart.getPlot(); 2152 if (axis.getPosition() == JRChartAxis.POSITION_RIGHT_OR_BOTTOM) 2153 { 2154 if (mainPlot instanceof CategoryPlot) 2155 ((CategoryPlot)mainPlot).setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); 2156 if (mainPlot instanceof XYPlot) 2157 ((XYPlot)mainPlot).setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT); 2158 } 2159 else 2160 { 2161 if (mainPlot instanceof CategoryPlot) 2162 ((CategoryPlot)mainPlot).setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); 2163 if (mainPlot instanceof XYPlot) 2164 ((XYPlot)mainPlot).setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); 2165 } 2166 } 2167 2168 int axisNumber = 0; 2170 while (iter.hasNext()) 2171 { 2172 axisNumber++; 2173 JRFillChartAxis chartAxis = (JRFillChartAxis)iter.next(); 2174 JRFillChart fillChart = chartAxis.getFillChart(); 2175 JFreeChart axisChart = fillChart.evaluateImage(evaluation).getChart(); 2176 2177 if (mainPlot instanceof CategoryPlot) 2184 { 2185 CategoryPlot mainCatPlot = (CategoryPlot)mainPlot; 2186 if (!(axisChart.getPlot() instanceof CategoryPlot)) 2187 { 2188 throw new JRException("You can not mix plot types in a MultiAxisChart"); 2189 } 2190 2191 CategoryPlot axisPlot = (CategoryPlot)axisChart.getPlot(); 2193 mainCatPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); 2194 if (chartAxis.getPosition() == JRChartAxis.POSITION_RIGHT_OR_BOTTOM) 2195 { 2196 mainCatPlot.setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT); 2197 } 2198 else 2199 { 2200 mainCatPlot.setRangeAxisLocation(axisNumber, AxisLocation.TOP_OR_LEFT); 2201 } 2202 2203 mainCatPlot.setDataset(axisNumber, axisPlot.getDataset()); 2205 mainCatPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); 2206 2207 mainCatPlot.setRenderer(axisNumber, axisPlot.getRenderer()); 2209 2210 configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot()); 2212 } 2213 else if (mainPlot instanceof XYPlot) 2214 { 2215 XYPlot mainXyPlot = (XYPlot)mainPlot; 2216 if (!(axisChart.getPlot() instanceof XYPlot)) 2217 { 2218 throw new JRException("You can not mix plot types in a MultiAxisChart"); 2219 } 2220 2221 XYPlot axisPlot = (XYPlot)axisChart.getPlot(); 2223 mainXyPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); 2224 if (chartAxis.getPosition() == JRChartAxis.POSITION_RIGHT_OR_BOTTOM) 2225 { 2226 mainXyPlot.setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT); 2227 } 2228 else 2229 { 2230 mainXyPlot.setRangeAxisLocation(axisNumber, AxisLocation.TOP_OR_LEFT); 2231 } 2232 2233 mainXyPlot.setDataset(axisNumber, axisPlot.getDataset()); 2235 mainXyPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); 2236 2237 mainXyPlot.setRenderer(axisNumber, axisPlot.getRenderer()); 2239 2240 configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot()); 2242 } 2243 else 2244 { 2245 throw new JRException("MultiAxis charts only support Category and XY plots."); 2246 } 2247 } 2248 return new JFreeChartRenderer(mainChart); 2249 } 2250 2251 protected void resolveElement(JRPrintElement element, byte evaluation) throws JRException 2252 { 2253 evaluateImage(evaluation); 2254 2255 copy((JRPrintImage) element); 2256 } 2257 2258 2259 public int getBookmarkLevel() 2260 { 2261 return ((JRChart)parent).getBookmarkLevel(); 2262 } 2263 2264 2267 public String getCustomizerClass() 2268 { 2269 return customizerClass; 2270 } 2271 2272 2275 public byte getBorder() 2276 { 2277 return JRStyleResolver.getBorder(this); 2278 } 2279 2280 public Byte getOwnBorder() 2281 { 2282 return ((JRBox)parent).getOwnBorder(); 2283 } 2284 2285 2288 public void setBorder(byte border) 2289 { 2290 } 2291 2292 2295 public void setBorder(Byte border) 2296 { 2297 } 2298 2299 2302 public Color getBorderColor() 2303 { 2304 return JRStyleResolver.getBorderColor(this, getForecolor()); 2305 } 2306 2307 public Color getOwnBorderColor() 2308 { 2309 return ((JRBox)parent).getOwnBorderColor(); 2310 } 2311 2312 2315 public void setBorderColor(Color borderColor) 2316 { 2317 } 2318 2319 2322 public int getPadding() 2323 { 2324 return JRStyleResolver.getPadding(this); 2325 } 2326 2327 public Integer getOwnPadding() 2328 { 2329 return ((JRBox)parent).getOwnPadding(); 2330 } 2331 2332 2335 public void setPadding(int padding) 2336 { 2337 } 2338 2339 2342 public void setPadding(Integer padding) 2343 { 2344 } 2345 2346 2349 public byte getTopBorder() 2350 { 2351 return JRStyleResolver.getTopBorder(this); 2352 } 2353 2354 2357 public Byte getOwnTopBorder() 2358 { 2359 return ((JRBox)parent).getOwnTopBorder(); 2360 } 2361 2362 2365 public void setTopBorder(byte topBorder) 2366 { 2367 } 2368 2369 2372 public void setTopBorder(Byte topBorder) 2373 { 2374 } 2375 2376 2379 public Color getTopBorderColor() 2380 { 2381 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 2382 } 2383 2384 2387 public Color getOwnTopBorderColor() 2388 { 2389 return ((JRBox)parent).getOwnTopBorderColor(); 2390 } 2391 2392 2395 public void setTopBorderColor(Color topBorderColor) 2396 { 2397 } 2398 2399 2402 public int getTopPadding() 2403 { 2404 return JRStyleResolver.getTopPadding(this); 2405 } 2406 2407 2410 public Integer getOwnTopPadding() 2411 { 2412 return ((JRBox)parent).getOwnTopPadding(); 2413 } 2414 2415 2418 public void setTopPadding(int topPadding) 2419 { 2420 } 2421 2422 2425 public void setTopPadding(Integer topPadding) 2426 { 2427 } 2428 2429 2432 public byte getLeftBorder() 2433 { 2434 return JRStyleResolver.getLeftBorder(this); 2435 } 2436 2437 2440 public Byte getOwnLeftBorder() 2441 { 2442 return ((JRBox)parent).getOwnLeftBorder(); 2443 } 2444 2445 2448 public void setLeftBorder(byte leftBorder) 2449 { 2450 } 2451 2452 2455 public void setLeftBorder(Byte leftBorder) 2456 { 2457 } 2458 2459 2462 public Color getLeftBorderColor() 2463 { 2464 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 2465 } 2466 2467 2470 public Color getOwnLeftBorderColor() 2471 { 2472 return ((JRBox)parent).getOwnLeftBorderColor(); 2473 } 2474 2475 2478 public void setLeftBorderColor(Color leftBorderColor) 2479 { 2480 } 2481 2482 2485 public int getLeftPadding() 2486 { 2487 return JRStyleResolver.getLeftPadding(this); 2488 } 2489 2490 2493 public Integer getOwnLeftPadding() 2494 { 2495 return ((JRBox)parent).getOwnLeftPadding(); 2496 } 2497 2498 2501 public void setLeftPadding(int leftPadding) 2502 { 2503 } 2504 2505 2508 public void setLeftPadding(Integer leftPadding) 2509 { 2510 } 2511 2512 2515 public byte getBottomBorder() 2516 { 2517 return JRStyleResolver.getBottomBorder(this); 2518 } 2519 2520 2523 public Byte getOwnBottomBorder() 2524 { 2525 return ((JRBox)parent).getOwnBottomBorder(); 2526 } 2527 2528 2531 public void setBottomBorder(byte bottomBorder) 2532 { 2533 } 2534 2535 2538 public void setBottomBorder(Byte bottomBorder) 2539 { 2540 } 2541 2542 2545 public Color getBottomBorderColor() 2546 { 2547 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 2548 } 2549 2550 2553 public Color getOwnBottomBorderColor() 2554 { 2555 return ((JRBox)parent).getOwnBottomBorderColor(); 2556 } 2557 2558 2561 public void setBottomBorderColor(Color bottomBorderColor) 2562 { 2563 } 2564 2565 2568 public int getBottomPadding() 2569 { 2570 return JRStyleResolver.getBottomPadding(this); 2571 } 2572 2573 2576 public Integer getOwnBottomPadding() 2577 { 2578 return ((JRBox)parent).getOwnBottomPadding(); 2579 } 2580 2581 2584 public void setBottomPadding(int bottomPadding) 2585 { 2586 } 2587 2588 2591 public void setBottomPadding(Integer bottomPadding) 2592 { 2593 } 2594 2595 2598 public byte getRightBorder() 2599 { 2600 return JRStyleResolver.getRightBorder(this); 2601 } 2602 2603 2606 public Byte getOwnRightBorder() 2607 { 2608 return ((JRBox)parent).getOwnRightBorder(); 2609 } 2610 2611 2614 public void setRightBorder(byte rightBorder) 2615 { 2616 } 2617 2618 2621 public void setRightBorder(Byte rightBorder) 2622 { 2623 } 2624 2625 2628 public Color getRightBorderColor() 2629 { 2630 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 2631 } 2632 2633 2636 public Color getOwnRightBorderColor() 2637 { 2638 return ((JRBox)parent).getOwnRightBorderColor(); 2639 } 2640 2641 2644 public void setRightBorderColor(Color rightBorderColor) 2645 { 2646 } 2647 2648 2651 public int getRightPadding() 2652 { 2653 return JRStyleResolver.getRightPadding(this); 2654 } 2655 2656 2659 public Integer getOwnRightPadding() 2660 { 2661 return ((JRBox)parent).getOwnRightPadding(); 2662 } 2663 2664 2667 public void setRightPadding(int rightPadding) 2668 { 2669 } 2670 2671 2674 public void setRightPadding(Integer rightPadding) 2675 { 2676 } 2677 2678 2679 2680 private void evaluateDatasetRun(byte evaluation) throws JRException 2681 { 2682 dataset.evaluateDatasetRun(evaluation); 2683 } 2684 2685 2686 public JRCloneable createClone(JRFillCloneFactory factory) 2687 { 2688 return null; 2690 } 2691 2692 2693 public JRHyperlinkParameter[] getHyperlinkParameters() 2694 { 2695 return ((JRChart) parent).getHyperlinkParameters(); 2696 } 2697 2698 2699 public String getLinkType() 2700 { 2701 return ((JRChart) parent).getLinkType(); 2702 } 2703 2704 2705 public JRExpression getHyperlinkTooltipExpression() 2706 { 2707 return ((JRChart) parent).getHyperlinkTooltipExpression(); 2708 } 2709 2710 2711 protected JFreeChartRenderer getCategoryRenderer(JFreeChart chart) 2712 { 2713 JFreeChartRenderer chartRenderer; 2714 JRFillCategoryDataset categoryDataset = (JRFillCategoryDataset) getDataset(); 2715 if (categoryDataset.hasItemHyperlinks()) 2716 { 2717 chartRenderer = new JRCategoryChartImageMapRenderer(chart, categoryDataset.getItemHyperlinks()); 2718 } 2719 else 2720 { 2721 chartRenderer = new JFreeChartRenderer(chart); 2722 } 2723 return chartRenderer; 2724 } 2725 2726 2727 protected JFreeChartRenderer getPieRenderer(JFreeChart chart) 2728 { 2729 JFreeChartRenderer chartRenderer; 2730 JRFillPieDataset pieDataset = (JRFillPieDataset) getDataset(); 2731 if (pieDataset.hasSectionHyperlinks()) 2732 { 2733 chartRenderer = new JRPieChartImageMapRenderer(chart, pieDataset.getSectionHyperlinks()); 2734 } 2735 else 2736 { 2737 chartRenderer = new JFreeChartRenderer(chart); 2738 } 2739 return chartRenderer; 2740 } 2741 2742 2743 protected JFreeChartRenderer getXYRenderer(JFreeChart chart) 2744 { 2745 JFreeChartRenderer chartRenderer; 2746 JRFillXyDataset xyDataset = (JRFillXyDataset) getDataset(); 2747 if (xyDataset.hasItemHyperlinks()) 2748 { 2749 chartRenderer = new JRXYChartImageMapRenderer(chart, xyDataset.getItemHyperlinks()); 2750 } 2751 else 2752 { 2753 chartRenderer = new JFreeChartRenderer(chart); 2754 } 2755 return chartRenderer; 2756 } 2757 2758 2759 protected JFreeChartRenderer getXYBarRenderer(JFreeChart chart) 2760 { 2761 JFreeChartRenderer chartRenderer; 2762 if( getDataset().getDatasetType() == JRChartDataset.TIMESERIES_DATASET ) { 2763 chartRenderer = getTimeSeriesRenderer(chart); 2764 } 2765 else if( getDataset().getDatasetType() == JRChartDataset.TIMEPERIOD_DATASET ){ 2766 chartRenderer = getTimePeriodRenderer(chart); 2767 } 2768 else if( getDataset().getDatasetType() == JRChartDataset.XY_DATASET ) { 2769 chartRenderer = getXYRenderer(chart); 2770 } else { 2771 chartRenderer = new JFreeChartRenderer(chart); 2772 } 2773 return chartRenderer; 2774 } 2775 2776 protected JFreeChartRenderer getXYZRenderer(JFreeChart chart) 2777 { 2778 JFreeChartRenderer chartRenderer; 2779 JRFillXyzDataset xyDataset = (JRFillXyzDataset) getDataset(); 2780 if (xyDataset.hasItemHyperlinks()) 2781 { 2782 chartRenderer = new JRXYChartImageMapRenderer(chart, xyDataset.getItemHyperlinks()); 2783 } 2784 else 2785 { 2786 chartRenderer = new JFreeChartRenderer(chart); 2787 } 2788 return chartRenderer; 2789 } 2790 2791 2792 protected JFreeChartRenderer getHighLowRenderer(JFreeChart chart) 2793 { 2794 JFreeChartRenderer chartRenderer; 2795 JRFillHighLowDataset hlDataset = (JRFillHighLowDataset) getDataset(); 2796 if (hlDataset.hasItemHyperlink()) 2797 { 2798 chartRenderer = new JRHighLowChartImageMapRenderer(chart, hlDataset.getItemHyperlinks()); 2799 } 2800 else 2801 { 2802 chartRenderer = new JFreeChartRenderer(chart); 2803 } 2804 return chartRenderer; 2805 } 2806 2807 2808 protected JFreeChartRenderer getTimeSeriesRenderer(JFreeChart chart) 2809 { 2810 JFreeChartRenderer chartRenderer; 2811 JRFillTimeSeriesDataset tsDataset = (JRFillTimeSeriesDataset) getDataset(); 2812 if (tsDataset.hasItemHyperlinks()) 2813 { 2814 chartRenderer = new JRTimeSeriesChartImageMapRenderer(chart, tsDataset.getItemHyperlinks()); 2815 } 2816 else 2817 { 2818 chartRenderer = new JFreeChartRenderer(chart); 2819 } 2820 return chartRenderer; 2821 } 2822 2823 2824 protected JFreeChartRenderer getTimePeriodRenderer(JFreeChart chart) 2825 { 2826 JFreeChartRenderer chartRenderer; 2827 JRFillTimePeriodDataset tpDataset = (JRFillTimePeriodDataset) getDataset(); 2828 if (tpDataset.hasItemHyperlinks()) 2829 { 2830 chartRenderer = new JRTimePeriodChartImageMapRenderer(chart, tpDataset.getItemHyperlinks()); 2831 } 2832 else 2833 { 2834 chartRenderer = new JFreeChartRenderer(chart); 2835 } 2836 return chartRenderer; 2837 } 2838} 2839 | Popular Tags |