KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > reportcharts > BarChartExpression


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 package org.pentaho.plugin.jfreereport.reportcharts;
14
15
16 import org.jfree.chart.ChartFactory;
17 import org.jfree.chart.JFreeChart;
18 import org.jfree.chart.plot.CategoryPlot;
19 import org.jfree.chart.plot.PlotOrientation;
20 import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
21 import org.jfree.chart.renderer.category.BarRenderer;
22 import org.jfree.chart.renderer.category.CategoryItemRenderer;
23 import org.jfree.chart.renderer.category.StackedBarRenderer;
24 import org.jfree.data.category.CategoryDataset;
25 import org.pentaho.core.session.IPentahoSession;
26
27 /**
28  * This class is for backward compatibility with previous build of the
29  * expression. Instead of using this class, use CategoricalChartExpression.
30  *
31  * @author mbatchel
32  *
33  */

34 public class BarChartExpression extends StackedCategoricalChartExpression {
35
36     private static final long serialVersionUID = 7082583397390897215L;
37
38     private boolean drawBarOutline;
39
40     private Double JavaDoc maxBarWidth;
41
42     private boolean stackedBarRenderPercentages = false;
43     
44     public BarChartExpression() {
45       super();
46     }
47
48     public BarChartExpression(IPentahoSession session) {
49         super(session);
50         // TODO Auto-generated constructor stub
51
}
52
53     public boolean isDrawBarOutline() {
54         return isChartSectionOutline();
55     }
56
57     public void setDrawBarOutline(boolean value) {
58         setChartSectionOutline(value);
59     }
60
61     public Double JavaDoc getMaxBarWidth() {
62         return maxBarWidth;
63     }
64
65     public void setMaxBarWidth(Double JavaDoc value) {
66         maxBarWidth = value;
67     }
68
69     public boolean isStackedBarRenderPercentages() {
70         return stackedBarRenderPercentages;
71     }
72
73     public void setStackedBarRenderPercentages(final boolean value) {
74         stackedBarRenderPercentages = value;
75     }
76
77     public JFreeChart getChart(CategoryDataset categoryDataset) {
78         JFreeChart rtn = null;
79         if (isThreeD()) {
80             if (isStacked()) {
81                 rtn = ChartFactory.createStackedBarChart3D(getTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, isHorizontal() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, isShowLegend(), false, false);
82             } else {
83                 rtn = ChartFactory.createBarChart3D(getTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, isHorizontal() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, isShowLegend(), false, false);
84             }
85         } else {
86             if (isStacked()) {
87                 rtn = ChartFactory.createStackedBarChart(getTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, isHorizontal() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, isShowLegend(), false, false);
88             } else {
89                 rtn = ChartFactory.createBarChart(getTitle(), getCategoryAxisLabel(), getValueAxisLabel(), categoryDataset, isHorizontal() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, isShowLegend(), false, false);
90             }
91         }
92         return rtn;
93
94     }
95
96     protected void setChartProperties(JFreeChart chart) {
97         super.setChartProperties(chart);
98         CategoryPlot cpl = chart.getCategoryPlot();
99         CategoryItemRenderer renderer = cpl.getRenderer();
100         AbstractCategoryItemRenderer acir = (AbstractCategoryItemRenderer) renderer;
101         BarRenderer br = (BarRenderer) acir;
102         br.setDrawBarOutline(drawBarOutline);
103         if (maxBarWidth != null) {
104             br.setMaximumBarWidth(maxBarWidth.doubleValue());
105         }
106         if ((isStacked()) && stackedBarRenderPercentages && (br instanceof StackedBarRenderer)) {
107             StackedBarRenderer sbr = (StackedBarRenderer) br;
108             sbr.setRenderAsPercentages(true);
109         }
110     }
111
112 }
113
Popular Tags