001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.plugin.jfreereport.reportcharts;
014:
015: import org.jfree.chart.ChartFactory;
016: import org.jfree.chart.JFreeChart;
017: import org.jfree.chart.plot.CategoryPlot;
018: import org.jfree.chart.plot.PlotOrientation;
019: import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
020: import org.jfree.chart.renderer.category.BarRenderer;
021: import org.jfree.chart.renderer.category.CategoryItemRenderer;
022: import org.jfree.chart.renderer.category.StackedBarRenderer;
023: import org.jfree.data.category.CategoryDataset;
024:
025: /**
026: * This class is for backward compatibility with previous build of the
027: * expression. Instead of using this class, use CategoricalChartExpression.
028: *
029: * @author mbatchel
030: *
031: */
032: public class BarChartExpression extends
033: StackedCategoricalChartExpression {
034:
035: private static final long serialVersionUID = 7082583397390897215L;
036:
037: private boolean drawBarOutline;
038:
039: private Double maxBarWidth;
040:
041: private boolean stackedBarRenderPercentages = false;
042:
043: public BarChartExpression() {
044: super ();
045: }
046:
047: public boolean isDrawBarOutline() {
048: return isChartSectionOutline();
049: }
050:
051: public void setDrawBarOutline(boolean value) {
052: setChartSectionOutline(value);
053: }
054:
055: public Double getMaxBarWidth() {
056: return maxBarWidth;
057: }
058:
059: public void setMaxBarWidth(Double value) {
060: maxBarWidth = value;
061: }
062:
063: public boolean isStackedBarRenderPercentages() {
064: return stackedBarRenderPercentages;
065: }
066:
067: public void setStackedBarRenderPercentages(final boolean value) {
068: stackedBarRenderPercentages = value;
069: }
070:
071: public JFreeChart getChart(CategoryDataset categoryDataset) {
072: JFreeChart rtn = null;
073: if (isThreeD()) {
074: if (isStacked()) {
075: rtn = ChartFactory.createStackedBarChart3D(getTitle(),
076: getCategoryAxisLabel(), getValueAxisLabel(),
077: categoryDataset,
078: isHorizontal() ? PlotOrientation.HORIZONTAL
079: : PlotOrientation.VERTICAL,
080: isShowLegend(), false, false);
081: } else {
082: rtn = ChartFactory.createBarChart3D(getTitle(),
083: getCategoryAxisLabel(), getValueAxisLabel(),
084: categoryDataset,
085: isHorizontal() ? PlotOrientation.HORIZONTAL
086: : PlotOrientation.VERTICAL,
087: isShowLegend(), false, false);
088: }
089: } else {
090: if (isStacked()) {
091: rtn = ChartFactory.createStackedBarChart(getTitle(),
092: getCategoryAxisLabel(), getValueAxisLabel(),
093: categoryDataset,
094: isHorizontal() ? PlotOrientation.HORIZONTAL
095: : PlotOrientation.VERTICAL,
096: isShowLegend(), false, false);
097: } else {
098: rtn = ChartFactory.createBarChart(getTitle(),
099: getCategoryAxisLabel(), getValueAxisLabel(),
100: categoryDataset,
101: isHorizontal() ? PlotOrientation.HORIZONTAL
102: : PlotOrientation.VERTICAL,
103: isShowLegend(), false, false);
104: }
105: }
106: return rtn;
107:
108: }
109:
110: protected void setChartProperties(JFreeChart chart) {
111: super .setChartProperties(chart);
112: CategoryPlot cpl = chart.getCategoryPlot();
113: CategoryItemRenderer renderer = cpl.getRenderer();
114: AbstractCategoryItemRenderer acir = (AbstractCategoryItemRenderer) renderer;
115: BarRenderer br = (BarRenderer) acir;
116: br.setDrawBarOutline(drawBarOutline);
117: if (maxBarWidth != null) {
118: br.setMaximumBarWidth(maxBarWidth.doubleValue());
119: }
120: if ((isStacked()) && stackedBarRenderPercentages
121: && (br instanceof StackedBarRenderer)) {
122: StackedBarRenderer sbr = (StackedBarRenderer) br;
123: sbr.setRenderAsPercentages(true);
124: }
125: }
126:
127: }
|