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.CategoryItemRenderer;
020: import org.jfree.chart.renderer.category.LineAndShapeRenderer;
021: import org.jfree.data.category.CategoryDataset;
022:
023: public class LineChartExpression extends CategoricalChartExpression {
024:
025: private static final long serialVersionUID = 816438776025760907L;
026:
027: private String lineStyle;
028:
029: private float lineWidth = 1.0f;
030:
031: private boolean markersVisible = false;
032:
033: public LineChartExpression() {
034: super ();
035: }
036:
037: public JFreeChart getChart(CategoryDataset categoryDataset) {
038: JFreeChart rtn = null;
039: if (isThreeD()) {
040: rtn = ChartFactory.createLineChart3D(getTitle(),
041: getCategoryAxisLabel(), getValueAxisLabel(),
042: categoryDataset,
043: isHorizontal() ? PlotOrientation.HORIZONTAL
044: : PlotOrientation.VERTICAL, isShowLegend(),
045: false, false);
046: } else {
047: rtn = ChartFactory.createLineChart(getTitle(),
048: getCategoryAxisLabel(), getValueAxisLabel(),
049: categoryDataset,
050: isHorizontal() ? PlotOrientation.HORIZONTAL
051: : PlotOrientation.VERTICAL, isShowLegend(),
052: false, false);
053: }
054: return rtn;
055: }
056:
057: protected void setChartProperties(JFreeChart chart) {
058: super .setChartProperties(chart);
059:
060: CategoryPlot cpl = chart.getCategoryPlot();
061: CategoryItemRenderer renderer = cpl.getRenderer();
062: renderer.setStroke(ChartConstants.translateLineStyle(lineWidth,
063: lineStyle));
064: if (renderer instanceof LineAndShapeRenderer) {
065: ((LineAndShapeRenderer) renderer)
066: .setShapesVisible(isMarkersVisible());
067: ((LineAndShapeRenderer) renderer)
068: .setBaseShapesFilled(isMarkersVisible());
069: }
070:
071: }
072:
073: /**
074: *
075: * @return returns the style set for the lines
076: * @see LINE_STYLE_SOLID_STR
077: * @see LINE_STYLE_DASH_STR
078: * @see LINE_STYLE_DOT_STR
079: * @see LINE_STYLE_DASHDOT_STR
080: * @see LINE_STYLE_DASHDOTDOT_STR
081: */
082: public String getLineStyle() {
083: return lineStyle;
084: }
085:
086: /**
087: *
088: * @param value set the style for all line series
089: * @see LINE_STYLE_SOLID_STR
090: * @see LINE_STYLE_DASH_STR
091: * @see LINE_STYLE_DOT_STR
092: * @see LINE_STYLE_DASHDOT_STR
093: * @see LINE_STYLE_DASHDOTDOT_STR
094: */
095: public void setLineStyle(String value) {
096: lineStyle = value;
097: }
098:
099: /**
100: *
101: * @return the width of all line series
102: * Valid values are float numbers zero or greater
103: */
104: public float getLineWidth() {
105: return lineWidth;
106: }
107:
108: /**
109: *
110: * @param lineWidth set the width of all line series
111: * Valid values are float numbers zero or greater
112: */
113: public void setLineWidth(float value) {
114: lineWidth = value;
115: }
116:
117: /**
118: *
119: * @return boolean whether the markers (data points) for all series are displayed
120: */
121: public boolean isMarkersVisible() {
122: return markersVisible;
123: }
124:
125: /**
126: *
127: * @param markersVisible set whether the markers (data points) for all series should be displayed
128: */
129: public void setMarkersVisible(boolean markersVisible) {
130: this.markersVisible = markersVisible;
131: }
132:
133: }
|