Source Code Cross Referenced for ChartReportEngine.java in  » Report » openreports » org » efs » openreports » engine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » openreports » org.efs.openreports.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2003 Erik Swenson - erik@oreports.com
003:         * 
004:         * This program is free software; you can redistribute it and/or modify it under
005:         * the terms of the GNU General Public License as published by the Free Software
006:         * Foundation; either version 2 of the License, or (at your option) any later
007:         * version.
008:         * 
009:         * This program is distributed in the hope that it will be useful, but WITHOUT
010:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011:         * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
012:         * details.
013:         * 
014:         * You should have received a copy of the GNU General Public License along with
015:         * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
016:         * Place - Suite 330, Boston, MA 02111-1307, USA.
017:         *  
018:         */
019:
020:        package org.efs.openreports.engine;
021:
022:        import java.awt.BasicStroke;
023:        import java.awt.Color;
024:        import java.awt.Font;
025:        import java.awt.image.BufferedImage;
026:        import java.io.IOException;
027:        import java.sql.Connection;
028:        import java.sql.PreparedStatement;
029:        import java.sql.ResultSet;
030:        import java.text.SimpleDateFormat;
031:        import java.util.ArrayList;
032:        import java.util.HashMap;
033:        import java.util.List;
034:        import java.util.Map;
035:
036:        import net.sf.jasperreports.engine.design.JRDesignQuery;
037:        import net.sf.jasperreports.engine.util.JRQueryExecuter;
038:
039:        import org.apache.log4j.Logger;
040:        import org.efs.openreports.engine.input.ReportEngineInput;
041:        import org.efs.openreports.engine.output.ChartEngineOutput;
042:        import org.efs.openreports.engine.output.ReportEngineOutput;
043:        import org.efs.openreports.objects.Report;
044:        import org.efs.openreports.objects.ReportChart;
045:        import org.efs.openreports.objects.ReportDataSource;
046:        import org.efs.openreports.objects.chart.CategoryChartValue;
047:        import org.efs.openreports.objects.chart.ChartValue;
048:        import org.efs.openreports.objects.chart.PieChartValue;
049:        import org.efs.openreports.objects.chart.TimeChartValue;
050:        import org.efs.openreports.objects.chart.XYChartValue;
051:        import org.efs.openreports.objects.chart.XYZChartValue;
052:        import org.efs.openreports.providers.DataSourceProvider;
053:        import org.efs.openreports.providers.DirectoryProvider;
054:        import org.efs.openreports.providers.PropertiesProvider;
055:        import org.efs.openreports.providers.ProviderException;
056:        import org.efs.openreports.util.LocalStrings;
057:        import org.efs.openreports.util.ORUtil;
058:        import org.efs.openreports.util.TimeSeriesURLGenerator;
059:        import org.efs.openreports.util.XYURLGenerator;
060:        import org.jfree.chart.ChartRenderingInfo;
061:        import org.jfree.chart.JFreeChart;
062:        import org.jfree.chart.axis.CategoryAxis;
063:        import org.jfree.chart.axis.CategoryAxis3D;
064:        import org.jfree.chart.axis.DateAxis;
065:        import org.jfree.chart.axis.NumberAxis;
066:        import org.jfree.chart.axis.NumberAxis3D;
067:        import org.jfree.chart.axis.ValueAxis;
068:        import org.jfree.chart.encoders.EncoderUtil;
069:        import org.jfree.chart.encoders.ImageFormat;
070:        import org.jfree.chart.entity.StandardEntityCollection;
071:        import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
072:        import org.jfree.chart.labels.StandardPieToolTipGenerator;
073:        import org.jfree.chart.labels.StandardXYToolTipGenerator;
074:        import org.jfree.chart.plot.CategoryPlot;
075:        import org.jfree.chart.plot.DialShape;
076:        import org.jfree.chart.plot.MeterInterval;
077:        import org.jfree.chart.plot.MeterPlot;
078:        import org.jfree.chart.plot.PiePlot3D;
079:        import org.jfree.chart.plot.PlotOrientation;
080:        import org.jfree.chart.plot.RingPlot;
081:        import org.jfree.chart.plot.ThermometerPlot;
082:        import org.jfree.chart.plot.XYPlot;
083:        import org.jfree.chart.renderer.category.AreaRenderer;
084:        import org.jfree.chart.renderer.category.BarRenderer3D;
085:        import org.jfree.chart.renderer.category.CategoryItemRenderer;
086:        import org.jfree.chart.renderer.category.StackedBarRenderer3D;
087:        import org.jfree.chart.renderer.xy.XYAreaRenderer;
088:        import org.jfree.chart.renderer.xy.XYItemRenderer;
089:        import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
090:        import org.jfree.chart.renderer.xy.StackedXYBarRenderer;
091:        import org.jfree.chart.renderer.xy.XYBarRenderer;
092:        import org.jfree.chart.urls.StandardCategoryURLGenerator;
093:        import org.jfree.chart.urls.StandardPieURLGenerator;
094:        import org.jfree.data.Range;
095:        import org.jfree.data.category.CategoryDataset;
096:        import org.jfree.data.category.DefaultCategoryDataset;
097:        import org.jfree.data.general.DefaultPieDataset;
098:        import org.jfree.data.general.DefaultValueDataset;
099:        import org.jfree.data.general.PieDataset;
100:        import org.jfree.data.time.Second;
101:        import org.jfree.data.time.TimeSeries;
102:        import org.jfree.data.time.TimeSeriesCollection;
103:        import org.jfree.data.xy.XYDataset;
104:        import org.jfree.data.xy.XYSeries;
105:        import org.jfree.data.xy.XYSeriesCollection;
106:        import org.jfree.ui.RectangleInsets;
107:
108:        /**
109:         * ChartReport ReportEngine implementation. Charts are generated using 
110:         * the JFreeReport library.
111:         * 
112:         * @author Erik Swenson
113:         * 
114:         */
115:
116:        public class ChartReportEngine extends ReportEngine {
117:            protected static Logger log = Logger
118:                    .getLogger(ChartReportEngine.class.getName());
119:
120:            public ChartReportEngine(DataSourceProvider dataSourceProvider,
121:                    DirectoryProvider directoryProvider,
122:                    PropertiesProvider propertiesProvider) {
123:                super (dataSourceProvider, directoryProvider, propertiesProvider);
124:            }
125:
126:            /**
127:             * Generates a ChartEngineOutput from a ReportEngineInput. The output consists 
128:             * of a byte[] containing a JPEG image.		
129:             */
130:            public ReportEngineOutput generateReport(ReportEngineInput input)
131:                    throws ProviderException {
132:                ReportChart chart = input.getReport().getReportChart();
133:                chart.setDescription(ORUtil.parseStringWithParameters(chart
134:                        .getDescription(), input.getParameters()));
135:
136:                ChartValue[] values = getChartValues(chart, input
137:                        .getParameters());
138:                if (values == null || values.length < 1)
139:                    throw new ProviderException(LocalStrings.ERROR_REPORT_EMPTY);
140:
141:                return createChartOutput(chart, values, input.getReport()
142:                        .isDisplayInline(), input.getParameters());
143:            }
144:
145:            /**
146:             * Executes the Chart query and builds an array of ChartValues from the results.
147:             */
148:            public ChartValue[] getChartValues(ReportChart reportChart,
149:                    Map parameters) throws ProviderException {
150:                Connection conn = null;
151:                PreparedStatement pStmt = null;
152:                ResultSet rs = null;
153:
154:                try {
155:                    ReportDataSource dataSource = reportChart.getDataSource();
156:                    conn = dataSourceProvider.getConnection(dataSource.getId());
157:
158:                    // Use JasperReports Query logic to parse parameters in chart
159:                    // queries
160:
161:                    JRDesignQuery query = new JRDesignQuery();
162:                    query.setText(reportChart.getQuery());
163:
164:                    // convert parameters to JRDesignParameters so they can be parsed
165:                    Map jrParameters = ORUtil
166:                            .buildJRDesignParameters(parameters);
167:
168:                    pStmt = JRQueryExecuter.getStatement(query, jrParameters,
169:                            parameters, conn);
170:
171:                    rs = pStmt.executeQuery();
172:
173:                    ArrayList<ChartValue> list = new ArrayList<ChartValue>();
174:
175:                    int chartType = reportChart.getChartType();
176:                    if (chartType == ReportChart.BAR_CHART
177:                            || chartType == ReportChart.AREA_CHART
178:                            || chartType == ReportChart.STACKED_BAR_CHART) {
179:                        while (rs.next()) {
180:                            CategoryChartValue catValue = new CategoryChartValue();
181:
182:                            catValue.setValue(rs.getDouble(1));
183:                            catValue.setSeries(rs.getString(2));
184:                            catValue.setCategory(rs.getString(3));
185:
186:                            list.add(catValue);
187:                        }
188:                    } else if (chartType == ReportChart.PIE_CHART
189:                            || chartType == ReportChart.RING_CHART) {
190:                        while (rs.next()) {
191:                            PieChartValue pieValue = new PieChartValue();
192:
193:                            pieValue.setValue(rs.getDouble(1));
194:                            pieValue.setKey(rs.getString(2));
195:
196:                            list.add(pieValue);
197:                        }
198:                    } else if (chartType == ReportChart.XY_CHART
199:                            || chartType == ReportChart.XY_AREA_CHART
200:                            || chartType == ReportChart.XY_BAR_CHART
201:                            || chartType == ReportChart.STACKED_XY_BAR_CHART) {
202:                        while (rs.next()) {
203:                            XYChartValue xyValue = new XYChartValue();
204:
205:                            xyValue.setSeries(rs.getString(1));
206:                            xyValue.setValue(rs.getDouble(2));
207:                            xyValue.setYValue(rs.getDouble(3));
208:
209:                            list.add(xyValue);
210:                        }
211:                    } else if (chartType == ReportChart.BUBBLE_CHART) {
212:                        while (rs.next()) {
213:                            XYZChartValue xyzValue = new XYZChartValue();
214:
215:                            xyzValue.setSeries(rs.getString(1));
216:                            xyzValue.setValue(rs.getDouble(2));
217:                            xyzValue.setYValue(rs.getDouble(3));
218:                            xyzValue.setZValue(rs.getDouble(4));
219:
220:                            list.add(xyzValue);
221:                        }
222:                    } else if (chartType == ReportChart.TIME_CHART
223:                            || chartType == ReportChart.TIME_AREA_CHART
224:                            || chartType == ReportChart.TIME_BAR_CHART
225:                            || chartType == ReportChart.STACKED_TIME_BAR_CHART) {
226:                        int columnType = rs.getMetaData().getColumnType(3);
227:
228:                        SimpleDateFormat dateFormat = new SimpleDateFormat(
229:                                "yyyy-MM-dd HH:mm:ss.SSS");
230:                        dateFormat.setTimeZone(java.util.TimeZone
231:                                .getTimeZone("UTC"));
232:
233:                        while (rs.next()) {
234:                            TimeChartValue timeValue = new TimeChartValue();
235:
236:                            timeValue.setSeries(rs.getString(1));
237:                            timeValue.setValue(rs.getDouble(2));
238:
239:                            if (columnType == 91 || columnType == 92
240:                                    || columnType == 93) //date, time, or timestamp
241:                            {
242:                                timeValue.setTime(rs.getTimestamp(3));
243:                            } else {
244:                                timeValue.setTime(dateFormat.parse(rs
245:                                        .getString(3)));
246:                            }
247:
248:                            list.add(timeValue);
249:                        }
250:                    } else if (chartType == ReportChart.DIAL_CHART
251:                            || chartType == ReportChart.THERMOMETER_CHART) {
252:                        while (rs.next()) {
253:                            ChartValue chartValue = new ChartValue();
254:                            chartValue.setValue(rs.getDouble(1));
255:
256:                            list.add(chartValue);
257:                        }
258:                    }
259:
260:                    ChartValue[] values = new ChartValue[list.size()];
261:                    list.toArray(values);
262:
263:                    return values;
264:                } catch (Exception e) {
265:                    log.error("getChartValues", e);
266:                    throw new ProviderException(LocalStrings.ERROR_SERVERSIDE);
267:                } finally {
268:                    try {
269:                        if (rs != null)
270:                            rs.close();
271:                        if (pStmt != null)
272:                            pStmt.close();
273:                        if (conn != null)
274:                            conn.close();
275:                    } catch (Exception c) {
276:                        log.error("Error closing");
277:                    }
278:                }
279:            }
280:
281:            private ChartEngineOutput createChartOutput(
282:                    ReportChart reportChart, ChartValue[] values,
283:                    boolean displayInline, Map parameters) {
284:                JFreeChart chart = null;
285:
286:                if (reportChart.getOverlayChart() != null) {
287:                    chart = createOverlayChart(reportChart, values,
288:                            displayInline, parameters);
289:                } else {
290:                    chart = createChart(reportChart, values, displayInline);
291:                }
292:
293:                if (chart == null)
294:                    return null;
295:
296:                chart.setBackgroundPaint(Color.WHITE);
297:
298:                ChartRenderingInfo info = new ChartRenderingInfo(
299:                        new StandardEntityCollection());
300:
301:                BufferedImage bufferedImage = chart.createBufferedImage(
302:                        reportChart.getWidth(), reportChart.getHeight(), info);
303:                byte[] image = null;
304:
305:                try {
306:                    image = EncoderUtil.encode(bufferedImage, ImageFormat.PNG);
307:                } catch (IOException ioe) {
308:                    log.warn(ioe);
309:                }
310:
311:                ChartEngineOutput chartOutput = new ChartEngineOutput();
312:                chartOutput.setContent(image);
313:                chartOutput
314:                        .setContentType(ReportEngineOutput.CONTENT_TYPE_JPEG);
315:                chartOutput.setChartRenderingInfo(info);
316:                chartOutput.setChartValues(values);
317:
318:                return chartOutput;
319:            }
320:
321:            private JFreeChart createChart(ReportChart reportChart,
322:                    ChartValue[] values, boolean displayInline) {
323:                JFreeChart chart = null;
324:
325:                switch (reportChart.getChartType()) {
326:                case ReportChart.BAR_CHART:
327:                    chart = createBarChart(reportChart, values, displayInline);
328:                    break;
329:                case ReportChart.PIE_CHART:
330:                    chart = createPieChart(reportChart, values, displayInline);
331:                    break;
332:                case ReportChart.XY_CHART:
333:                    chart = createXYChart(reportChart, values, displayInline);
334:                    break;
335:                case ReportChart.TIME_CHART:
336:                    chart = createTimeChart(reportChart, values, displayInline);
337:                    break;
338:                case ReportChart.RING_CHART:
339:                    chart = createRingChart(reportChart, values, displayInline);
340:                    break;
341:                case ReportChart.AREA_CHART:
342:                    chart = createAreaChart(reportChart, values, displayInline);
343:                    break;
344:                case ReportChart.XY_AREA_CHART:
345:                    chart = createXYAreaChart(reportChart, values,
346:                            displayInline);
347:                    break;
348:                case ReportChart.TIME_AREA_CHART:
349:                    chart = createTimeAreaChart(reportChart, values,
350:                            displayInline);
351:                    break;
352:                case ReportChart.STACKED_BAR_CHART:
353:                    chart = createStackedBarChart(reportChart, values,
354:                            displayInline);
355:                    break;
356:                case ReportChart.DIAL_CHART:
357:                    chart = createDialChart(reportChart, values, displayInline);
358:                    break;
359:                case ReportChart.THERMOMETER_CHART:
360:                    chart = createThermometerChart(reportChart, values,
361:                            displayInline);
362:                    break;
363:                case ReportChart.XY_BAR_CHART:
364:                    chart = createXYBarChart(reportChart, values, displayInline);
365:                    break;
366:                case ReportChart.STACKED_XY_BAR_CHART:
367:                    chart = createStackedXYBarChart(reportChart, values,
368:                            displayInline);
369:                    break;
370:                case ReportChart.TIME_BAR_CHART:
371:                    chart = createTimeBarChart(reportChart, values,
372:                            displayInline);
373:                    break;
374:                case ReportChart.STACKED_TIME_BAR_CHART:
375:                    chart = createStackedTimeBarChart(reportChart, values,
376:                            displayInline);
377:                    break;
378:                default:
379:                    break;
380:                }
381:
382:                return chart;
383:            }
384:
385:            private JFreeChart createBarChart(ReportChart reportChart,
386:                    ChartValue[] values, boolean displayInline) {
387:                CategoryDataset dataset = createCategoryDataset(values);
388:
389:                CategoryAxis3D categoryAxis = new CategoryAxis3D(reportChart
390:                        .getXAxisLabel());
391:                ValueAxis valueAxis = new NumberAxis3D(reportChart
392:                        .getYAxisLabel());
393:
394:                BarRenderer3D renderer = new BarRenderer3D();
395:                renderer
396:                        .setToolTipGenerator(new StandardCategoryToolTipGenerator());
397:
398:                if (reportChart.getDrillDownReport() != null) {
399:                    renderer
400:                            .setItemURLGenerator(new StandardCategoryURLGenerator(
401:                                    "executeReport.action?displayInline="
402:                                            + displayInline
403:                                            + "&exportType=0&reportId="
404:                                            + reportChart.getDrillDownReport()
405:                                                    .getId(), "series",
406:                                    ReportChart.DRILLDOWN_PARAMETER));
407:                }
408:
409:                CategoryPlot plot = new CategoryPlot(dataset, categoryAxis,
410:                        valueAxis, renderer);
411:                plot.setOrientation(PlotOrientation.VERTICAL);
412:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
413:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
414:                }
415:
416:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
417:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
418:                                .isShowLegend());
419:
420:                return chart;
421:            }
422:
423:            private JFreeChart createXYBarChart(ReportChart reportChart,
424:                    ChartValue[] values, boolean displayInline) {
425:                XYDataset dataset = createXYDataset(values);
426:
427:                NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel());
428:                NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel());
429:
430:                XYBarRenderer renderer = new XYBarRenderer();
431:                renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
432:
433:                XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
434:                plot.setOrientation(PlotOrientation.VERTICAL);
435:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
436:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
437:                }
438:
439:                return new JFreeChart(reportChart.getTitle(),
440:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
441:                                .isShowLegend());
442:            }
443:
444:            private JFreeChart createPieChart(ReportChart reportChart,
445:                    ChartValue[] values, boolean displayInline) {
446:                PieDataset dataset = createPieDataset(values);
447:
448:                PiePlot3D plot = new PiePlot3D(dataset);
449:                plot.setToolTipGenerator(new StandardPieToolTipGenerator());
450:
451:                if (reportChart.getDrillDownReport() != null) {
452:                    plot.setURLGenerator(new StandardPieURLGenerator(
453:                            "executeReport.action?displayInline="
454:                                    + displayInline + "&exportType=0&reportId="
455:                                    + reportChart.getDrillDownReport().getId(),
456:                            ReportChart.DRILLDOWN_PARAMETER, "pieIndex"));
457:                }
458:
459:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
460:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
461:                                .isShowLegend());
462:
463:                return chart;
464:            }
465:
466:            private JFreeChart createRingChart(ReportChart reportChart,
467:                    ChartValue[] values, boolean displayInline) {
468:                PieDataset dataset = createPieDataset(values);
469:
470:                RingPlot plot = new RingPlot(dataset);
471:                plot.setToolTipGenerator(new StandardPieToolTipGenerator());
472:
473:                if (reportChart.getDrillDownReport() != null) {
474:                    plot.setURLGenerator(new StandardPieURLGenerator(
475:                            "executeReport.action?displayInline="
476:                                    + displayInline + "&exportType=0&reportId="
477:                                    + reportChart.getDrillDownReport().getId(),
478:                            ReportChart.DRILLDOWN_PARAMETER, "pieIndex"));
479:                }
480:
481:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
482:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
483:                                .isShowLegend());
484:
485:                return chart;
486:            }
487:
488:            private JFreeChart createXYChart(ReportChart reportChart,
489:                    ChartValue[] values, boolean displayInline) {
490:                XYDataset dataset = createXYDataset(values);
491:
492:                NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel());
493:                NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel());
494:
495:                XYItemRenderer renderer = new XYLineAndShapeRenderer();
496:                renderer
497:                        .setBaseToolTipGenerator(new StandardXYToolTipGenerator());
498:
499:                if (reportChart.getDrillDownReport() != null) {
500:                    renderer.setURLGenerator(new XYURLGenerator(
501:                            "executeReport.action?displayInline="
502:                                    + displayInline + "&exportType=0&reportId="
503:                                    + reportChart.getDrillDownReport().getId(),
504:                            "series", ReportChart.DRILLDOWN_PARAMETER));
505:                }
506:
507:                XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
508:                plot.setOrientation(PlotOrientation.VERTICAL);
509:
510:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
511:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
512:                }
513:
514:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
515:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
516:                                .isShowLegend());
517:
518:                return chart;
519:            }
520:
521:            private JFreeChart createTimeChart(ReportChart reportChart,
522:                    ChartValue[] values, boolean displayInline) {
523:                XYDataset dataset = createTimeDataset(values);
524:
525:                ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel());
526:                NumberAxis valueAxis = new NumberAxis(reportChart
527:                        .getYAxisLabel());
528:
529:                XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
530:                renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator
531:                        .getTimeSeriesInstance());
532:
533:                if (reportChart.getDrillDownReport() != null) {
534:                    renderer.setURLGenerator(new TimeSeriesURLGenerator(
535:                            "executeReport.action?displayInline="
536:                                    + displayInline + "&exportType=0&reportId="
537:                                    + reportChart.getDrillDownReport().getId(),
538:                            "series", ReportChart.DRILLDOWN_PARAMETER));
539:                }
540:
541:                XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
542:                plot.setOrientation(PlotOrientation.VERTICAL);
543:
544:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
545:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
546:                }
547:
548:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
549:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
550:                                .isShowLegend());
551:
552:                return chart;
553:            }
554:
555:            private JFreeChart createTimeBarChart(ReportChart reportChart,
556:                    ChartValue[] values, boolean displayInline) {
557:                JFreeChart chart = null;
558:
559:                XYDataset dataset = createTimeDataset(values);
560:
561:                ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel());
562:                NumberAxis valueAxis = new NumberAxis(reportChart
563:                        .getYAxisLabel());
564:
565:                XYItemRenderer renderer = new XYBarRenderer();
566:                renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator
567:                        .getTimeSeriesInstance());
568:
569:                XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
570:                plot.setOrientation(PlotOrientation.VERTICAL);
571:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
572:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
573:                }
574:
575:                chart = new JFreeChart(reportChart.getTitle(),
576:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
577:                                .isShowLegend());
578:
579:                return chart;
580:            }
581:
582:            private JFreeChart createStackedTimeBarChart(
583:                    ReportChart reportChart, ChartValue[] values,
584:                    boolean displayInline) {
585:                XYDataset dataset = createTimeDataset(values);
586:
587:                ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel());
588:                NumberAxis valueAxis = new NumberAxis(reportChart
589:                        .getYAxisLabel());
590:
591:                XYItemRenderer renderer = new StackedXYBarRenderer();
592:                renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator
593:                        .getTimeSeriesInstance());
594:
595:                XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
596:                plot.setOrientation(PlotOrientation.VERTICAL);
597:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
598:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
599:                }
600:
601:                return new JFreeChart(reportChart.getTitle(),
602:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
603:                                .isShowLegend());
604:            }
605:
606:            private JFreeChart createOverlayChart(ReportChart reportChart,
607:                    ChartValue[] values, boolean displayInline, Map parameters) {
608:                JFreeChart chart = createChart(reportChart, values,
609:                        displayInline);
610:
611:                try {
612:                    ReportChart overlayReportChart = reportChart
613:                            .getOverlayChart();
614:                    ChartValue[] overlayValues = getChartValues(
615:                            overlayReportChart, parameters);
616:
617:                    JFreeChart overlayChart = createChart(overlayReportChart,
618:                            overlayValues, displayInline);
619:
620:                    XYPlot plot = (XYPlot) chart.getPlot();
621:                    XYPlot overlayPlot = (XYPlot) overlayChart.getPlot();
622:
623:                    NumberAxis axis = new NumberAxis(overlayReportChart
624:                            .getYAxisLabel());
625:                    axis.setUpperMargin(.25);
626:
627:                    plot.setRangeAxis(1, axis);
628:                    plot.setDataset(1, overlayPlot.getDataset());
629:                    plot.setRangeAxis(1, axis);
630:                    plot.mapDatasetToRangeAxis(1, 1);
631:                    plot.setRenderer(1, overlayPlot.getRenderer());
632:                } catch (Exception e) {
633:                    log.error("createOverlayChart", e);
634:                }
635:
636:                return chart;
637:            }
638:
639:            private JFreeChart createAreaChart(ReportChart reportChart,
640:                    ChartValue[] values, boolean displayInline) {
641:                CategoryDataset dataset = createCategoryDataset(values);
642:
643:                CategoryAxis3D categoryAxis = new CategoryAxis3D(reportChart
644:                        .getXAxisLabel());
645:                categoryAxis.setCategoryMargin(0.0);
646:
647:                ValueAxis valueAxis = new NumberAxis3D(reportChart
648:                        .getYAxisLabel());
649:
650:                AreaRenderer renderer = new AreaRenderer();
651:                renderer
652:                        .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
653:
654:                if (reportChart.getDrillDownReport() != null) {
655:                    renderer
656:                            .setBaseItemURLGenerator(new StandardCategoryURLGenerator(
657:                                    "executeReport.action?displayInline="
658:                                            + displayInline
659:                                            + "&exportType=0&reportId="
660:                                            + reportChart.getDrillDownReport()
661:                                                    .getId(), "series",
662:                                    ReportChart.DRILLDOWN_PARAMETER));
663:                }
664:
665:                CategoryPlot plot = new CategoryPlot(dataset, categoryAxis,
666:                        valueAxis, renderer);
667:                plot.setOrientation(PlotOrientation.VERTICAL);
668:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
669:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
670:                }
671:
672:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
673:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
674:                                .isShowLegend());
675:
676:                return chart;
677:            }
678:
679:            private JFreeChart createTimeAreaChart(ReportChart reportChart,
680:                    ChartValue[] values, boolean displayInline) {
681:                XYDataset dataset = createTimeDataset(values);
682:
683:                ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel());
684:                NumberAxis valueAxis = new NumberAxis(reportChart
685:                        .getYAxisLabel());
686:
687:                XYAreaRenderer renderer = new XYAreaRenderer();
688:                renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator
689:                        .getTimeSeriesInstance());
690:
691:                if (reportChart.getDrillDownReport() != null) {
692:                    renderer.setURLGenerator(new TimeSeriesURLGenerator(
693:                            "executeReport.action?displayInline="
694:                                    + displayInline + "&exportType=0&reportId="
695:                                    + reportChart.getDrillDownReport().getId(),
696:                            "series", ReportChart.DRILLDOWN_PARAMETER));
697:                }
698:
699:                XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
700:                plot.setOrientation(PlotOrientation.VERTICAL);
701:
702:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
703:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
704:                }
705:
706:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
707:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
708:                                .isShowLegend());
709:
710:                return chart;
711:            }
712:
713:            private JFreeChart createXYAreaChart(ReportChart reportChart,
714:                    ChartValue[] values, boolean displayInline) {
715:                XYDataset dataset = createXYDataset(values);
716:
717:                NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel());
718:                xAxis.setAutoRangeIncludesZero(false);
719:
720:                NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel());
721:
722:                XYAreaRenderer renderer = new XYAreaRenderer();
723:                renderer
724:                        .setBaseToolTipGenerator(new StandardXYToolTipGenerator());
725:
726:                if (reportChart.getDrillDownReport() != null) {
727:                    renderer.setURLGenerator(new XYURLGenerator(
728:                            "executeReport.action?displayInline="
729:                                    + displayInline + "&exportType=0&reportId="
730:                                    + reportChart.getDrillDownReport().getId(),
731:                            "series", ReportChart.DRILLDOWN_PARAMETER));
732:                }
733:
734:                XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
735:                plot.setForegroundAlpha(0.5F);
736:                plot.setOrientation(PlotOrientation.VERTICAL);
737:
738:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
739:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
740:                }
741:
742:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
743:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
744:                                .isShowLegend());
745:
746:                return chart;
747:            }
748:
749:            private JFreeChart createStackedBarChart(ReportChart reportChart,
750:                    ChartValue[] values, boolean displayInline) {
751:                CategoryDataset dataset = createCategoryDataset(values);
752:
753:                CategoryAxis categoryAxis = new CategoryAxis3D(reportChart
754:                        .getXAxisLabel());
755:                ValueAxis valueAxis = new NumberAxis3D(reportChart
756:                        .getYAxisLabel());
757:
758:                CategoryItemRenderer renderer = new StackedBarRenderer3D();
759:                renderer
760:                        .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
761:
762:                if (reportChart.getDrillDownReport() != null) {
763:                    renderer
764:                            .setBaseItemURLGenerator(new StandardCategoryURLGenerator(
765:                                    "executeReport.action?displayInline="
766:                                            + displayInline
767:                                            + "&exportType=0&reportId="
768:                                            + reportChart.getDrillDownReport()
769:                                                    .getId(), "series",
770:                                    ReportChart.DRILLDOWN_PARAMETER));
771:                }
772:
773:                CategoryPlot plot = new CategoryPlot(dataset, categoryAxis,
774:                        valueAxis, renderer);
775:                plot.setOrientation(PlotOrientation.VERTICAL);
776:
777:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
778:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
779:                }
780:
781:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
782:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
783:                                .isShowLegend());
784:
785:                return chart;
786:            }
787:
788:            private JFreeChart createStackedXYBarChart(ReportChart reportChart,
789:                    ChartValue[] values, boolean displayInline) {
790:                XYDataset dataset = createXYDataset(values);
791:
792:                NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel());
793:                NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel());
794:
795:                StackedXYBarRenderer renderer = new StackedXYBarRenderer();
796:                renderer
797:                        .setBaseToolTipGenerator(new StandardXYToolTipGenerator());
798:
799:                XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
800:                plot.setOrientation(PlotOrientation.VERTICAL);
801:                if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) {
802:                    plot.setOrientation(PlotOrientation.HORIZONTAL);
803:                }
804:
805:                return new JFreeChart(reportChart.getTitle(),
806:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
807:                                .isShowLegend());
808:            }
809:
810:            private JFreeChart createDialChart(ReportChart reportChart,
811:                    ChartValue[] values, boolean displayInline) {
812:                DefaultValueDataset dataset = createDefaultValueDataset(values);
813:
814:                MeterPlot plot = new MeterPlot(dataset);
815:                plot.setRange(new Range(0, 60));
816:                plot.addInterval(new MeterInterval("Normal", new Range(0.0,
817:                        35.0), Color.lightGray, new BasicStroke(2.0f),
818:                        new Color(0, 255, 0, 64)));
819:                plot.addInterval(new MeterInterval("Warning", new Range(35.0,
820:                        50.0), Color.lightGray, new BasicStroke(2.0f),
821:                        new Color(255, 255, 0, 64)));
822:                plot.addInterval(new MeterInterval("Critical", new Range(50.0,
823:                        60.0), Color.lightGray, new BasicStroke(2.0f),
824:                        new Color(255, 0, 0, 128)));
825:                plot.setNeedlePaint(Color.darkGray);
826:                plot.setDialBackgroundPaint(Color.white);
827:                plot.setDialOutlinePaint(Color.gray);
828:                plot.setDialShape(DialShape.CHORD);
829:                plot.setMeterAngle(260);
830:                plot.setTickLabelsVisible(true);
831:                plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10));
832:                plot.setTickLabelPaint(Color.darkGray);
833:                plot.setTickSize(5.0);
834:                plot.setTickPaint(Color.lightGray);
835:                plot.setValuePaint(Color.black);
836:                plot.setValueFont(new Font("Dialog", Font.BOLD, 14));
837:
838:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
839:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
840:                                .isShowLegend());
841:
842:                return chart;
843:            }
844:
845:            private JFreeChart createThermometerChart(ReportChart reportChart,
846:                    ChartValue[] values, boolean displayInline) {
847:                DefaultValueDataset dataset = createDefaultValueDataset(values);
848:
849:                ThermometerPlot plot = new ThermometerPlot(dataset);
850:
851:                plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
852:                plot.setPadding(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
853:                plot.setThermometerStroke(new BasicStroke(2.0f));
854:                plot.setThermometerPaint(Color.lightGray);
855:                plot.setUnits(ThermometerPlot.UNITS_FAHRENHEIT);
856:
857:                JFreeChart chart = new JFreeChart(reportChart.getTitle(),
858:                        JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart
859:                                .isShowLegend());
860:
861:                return chart;
862:            }
863:
864:            private CategoryDataset createCategoryDataset(ChartValue[] values) {
865:                DefaultCategoryDataset dataset = new DefaultCategoryDataset();
866:
867:                for (int i = 0; i < values.length; i++) {
868:                    CategoryChartValue value = (CategoryChartValue) values[i];
869:                    dataset.addValue(value.getValue(), value.getSeries(), value
870:                            .getCategory());
871:                }
872:
873:                return dataset;
874:            }
875:
876:            private PieDataset createPieDataset(ChartValue[] values) {
877:                DefaultPieDataset dataset = new DefaultPieDataset();
878:
879:                for (int i = 0; i < values.length; i++) {
880:                    PieChartValue value = (PieChartValue) values[i];
881:                    dataset.setValue(value.getKey(), value.getValue());
882:                }
883:
884:                return dataset;
885:            }
886:
887:            private XYDataset createXYDataset(ChartValue[] values) {
888:                XYSeries series = null;
889:                XYSeriesCollection seriesCollection = new XYSeriesCollection();
890:
891:                for (int i = 0; i < values.length; i++) {
892:                    XYChartValue value = (XYChartValue) values[i];
893:
894:                    if (series == null
895:                            || !series.getKey().equals(value.getSeries())) {
896:                        if (series != null) {
897:                            seriesCollection.addSeries(series);
898:                        }
899:
900:                        series = new XYSeries(value.getSeries());
901:                    }
902:
903:                    series.add(value.getValue(), value.getYValue());
904:                }
905:
906:                if (series != null)
907:                    seriesCollection.addSeries(series);
908:
909:                return seriesCollection;
910:            }
911:
912:            private XYDataset createTimeDataset(ChartValue[] values) {
913:                TimeSeries series = null;
914:                TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
915:
916:                for (int i = 0; i < values.length; i++) {
917:                    TimeChartValue value = (TimeChartValue) values[i];
918:
919:                    if (series == null
920:                            || !series.getKey().equals(value.getSeries())) {
921:                        if (series != null) {
922:                            seriesCollection.addSeries(series);
923:                        }
924:
925:                        series = new TimeSeries(value.getSeries(), Second.class);
926:                    }
927:
928:                    series.add(new Second(value.getTime()), value.getValue());
929:                }
930:
931:                seriesCollection.addSeries(series);
932:
933:                return seriesCollection;
934:            }
935:
936:            private DefaultValueDataset createDefaultValueDataset(
937:                    ChartValue[] values) {
938:                DefaultValueDataset dataset = new DefaultValueDataset(values[0]
939:                        .getValue());
940:                return dataset;
941:            }
942:
943:            public List buildParameterList(Report report)
944:                    throws ProviderException {
945:                throw new ProviderException(
946:                        "ChartReportEngine: buildParameterList not implemented.");
947:            }
948:
949:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.