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