intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Pentaho Reporting 3.5 for Java Developers- P1

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

127
lượt xem
34
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Cuốn sách này bắt đầu với một số ví dụ để giúp bạn quen thuộc với các công cụ và công nghệ của các báo cáo Pentaho Suite. Sau đó, với các ví dụ khác, nó đi vào đối tượng cao cấp như biểu đồ, phụ báo cáo, các tab qua, cũng như các thế hệ API của báo cáo. Ngoài ra còn có các chi tiết và các ví dụ về mở rộng nguồn mở của Pentaho báo cáo động cơ. Người đọc sẽ tìm hiểu các ins and outs của Designer Pentaho Báo cáo, bao gồm một cheat...

Chủ đề:
Lưu

Nội dung Text: Pentaho Reporting 3.5 for Java Developers- P1

  1. Pentaho Reporting 3.5 for Java Developers Create advanced reports, including cross tabs, sub-reports, and charts that connect to practically any data source using open source Pentaho Reporting Will Gorman BIRMINGHAM - MUMBAI
  2. Pentaho Reporting 3.5 for Java Developers Copyright © 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2009 Production Reference: 1310809 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847193-19-3 www.packtpub.com Cover Image by Vinayak Chittar (vinayak.chittar@gmail.com)
  3. Credits Author Editorial Team Leader Will Gorman Gagandeep Singh Reviewers Project Team Leader Jem Matzan Priya Mukherji Kurtis Cruzada Project Coordinators Acquisition Editor Zainab Bagasrawala James Lumsden Lata Basantani Development Editor Proofreader Dhiraj Chandiramani Laura Booth Technical Editor Production Coordinator Gaurav Datar Adline Swetha Jesuthas Indexer Cover Work Rekha Nair Adline Swetha Jesuthas Drawing Coordinator Nilesh R. Mohite
  4. Foreword During the course of the last 8000 years, no other invention has driven the course of human development more than the ancient art of business reporting. In the ancient city states of Mesopotamia, the rulers of the fast growing states carved inventory lists and tax records into stone plates. For the first time in human history this enabled the management of large distributed empires, armies, and organizations. Fast-forward a few thousand years, and the art reporting is still in fashion. Even today reporting drives empires, not ones rules by kings, but empires created by entrepreneurs as well as large-scale public traded companies. Carving lists and numbers in stones has been replaced by electrons traveling at the speed of light to deliver critical information to the leaders of today's business world. When I first came to JFreeReport, I did not care about the big players. All I needed was a printing system to create long and boring printouts at reasonable speed and cost. None of the commercial vendors were able or willing to solve my needs, and hence I stumbled (quite accidentally) over JFreeReport. After some time extending, optimizing, and debugging in the reporting engine, I was addicted to it. Eight years later, the project has changed radically from its early roots. As we grew from simple printing to fully featured BI-reporting, we left the name "JFreeReport" behind and became known as "Pentaho Reporting". But this original love has never diminished and all these years later, the project has grown stronger to now challenge even the age-old commercial offerings in their own space. The book you're holding in your hand right now marks an important milestone in Pentaho Reporting's history. For the very first time, we are now able to point our users, developers, and partners to a professionally written document that covers all aspects of the Pentaho reporting engine. After eight years of sending developers into the Java code to learn how a feature is working, this is a remarkable and welcome change.
  5. If you want to understand the concepts used in Pentaho Reporting or want to add reporting capabilities to your own application, you will find this book an invaluable companion on your journey. As the book guides you from the very simple examples, to the fully embedded reporting scenarios, the knowledge in the book will guide you safely through all your tasks so that you can become productive very fast. Business Reporting should be available for everyone who has a need for it, so take control of your data. Thomas Morgner Chief Architect, Pentaho Reporting
  6. About the Author Will Gorman is an Engineering Team Lead at Pentaho. He works on a variety of Pentaho's products, including Reporting, Analysis, Dashboards, Metadata, and the BI Server. Will started his career at GE Research, and earned his Masters degree in Computer Science at Rensselaer Polytechnic Institute in Troy, New York. Over the years, Will has given many speeches, including topics at local Java User Groups and has also published technical papers in journals such as Neurology. Will is originally from Cincinnati, Ohio and now lives in Orlando, Florida, the headquarters of Pentaho. This book was possible thanks to all the great help from Pentaho's Reporting team, including Thomas Morgner, the lead architect and founder of Pentaho Reporting, Kurtis Cruzada, Pentaho Reporting's Product Manager, Jem Matzan, documentation lead for Pentaho Reporting, and many of the Pentaho engineers who work on Pentaho Reporting and Pentaho Report Designer, including David Kincade, Mike D'Amour, Ezequiel Cuellar, and Bill Seyler. I'd also like to thank all those in the open source community who have contributed to Pentaho Reporting. I also want to thank the founders of Pentaho, Doug Moran, James Dixon, Marc Bachelor, and Richard Daley, who make every day at Pentaho entertaining and enlightening. Finally, I want to give special thanks to my patient wife Laura and our wonderful son Luke, who both gave me their full support during the many weekends and holidays of book writing.
  7. About the Reviewers Jem Matzan is the author of hundreds of information technology articles and reviews. Apart from being an author, he is a ghostwriter, editor of several technology-oriented books, and a software documentation specialist. Kurtis Cruzada is a graduate of the University of Central Florida majoring in Accounting and minoring in Computer Science, and also holds an MBA with a focus in Accounting Information Systems. Kurtis began his career in the Business Intelligence field in the early 1990s. In late 1990s, Kurtis joined Arbor Software/ Hyperion Solutions where he managed Wired for OLAP (Hyperion Analyzer and Web Analytics) and Hyperion's BI Workspace, which later became the collective front-end framework for all the web-based Hyperion products. In late 2005, Kurtis joined Pentaho as a Senior Product Manager primarily focusing on Reporting and the BI Platform. I would like to thank my wife, Tracy and my kids, Riley, Mallory and Kai for supporting me throughout my career and endeavors.
  8. Table of Contents Preface 1 Chapter 1: An Introduction to Pentaho Reporting 7 Typical uses of Pentaho Reporting 8 Operational reporting 8 Business intelligence reporting 9 Financial reporting 9 Production reporting 11 Pentaho Reporting history 12 Pentaho Reporting timeline 13 Feature overview 14 An advanced reporting algorithm 14 A multitude of available data sources 14 A wide variety of output formats 15 Pixel accurate rich formatting 17 Embedded charts 18 Report parameterization 18 Formulas and style expressions 19 Sub-reports 19 Cross Tab Reports 20 Interactive reporting 20 Rich authoring tools 22 Reporting server 23 Java API for building reports 23 Extensibility 23 A business friendly open source license 23 Pentaho reporting roadmap 24 Pentaho Reporting architecture 24
  9. Table of Contents LibBase 24 LibDocBundle 25 LibFonts 25 LibFormat 25 LibFormula 25 LibLoader 25 LibRepository 25 LibSerializer 26 LibXml 26 Report Engine Core 26 Report Engine Extensions 26 Summary 27 Chapter 2: Pentaho Reporting Client and Enterprise Examples 29 Pentaho Reporting and example prerequisites 29 Setting up Pentaho Reporting 30 Building your first report 32 Report Designer introduction 32 Creating and configuring your first data source 34 Report layout 35 Creating the report title 36 Creating column headings 36 Populating the details band 37 Creating a report summary 38 Previewing and saving your report 38 Embedding your report in a Swing application 40 Setting up the Swing example application 40 Incorporating Pentaho Reporting into the application 43 Embedding your report in an enterprise web application 47 Setting up the example Tomcat application 47 Incorporating Pentaho Reporting into the web application 49 Adding additional output formats 53 Summary 54 Chapter 3: Pentaho Reporting Examples in the Real World 55 Setting up the example data source 55 ElectroBarn inventory report 58 Configuring the data source 58 Creating a query 59 Creating the Report Header and Page Footer 60 Defining the Group Header 62 Defining the Details band 63 Defining the Group Footer and the Report Footer band 64 [ ii ]
  10. Table of Contents Adding a pie chart 65 Incorporating the inventory report into your J2EE environment 66 Adding report selection as an input to the servlet 66 Compiling and deploying the report servlet 66 End of the day cashier balances 68 Configuring an input parameter 68 Configuring the data source query 70 Creating the Report Header and Page Footer 71 Defining the Details band 72 Defining the Group bands 72 Defining the main Group Header 73 Incorporating the End of Day report into your J2EE environment 76 ElectroBarn invoice example 78 Configuring the data source query 79 Defining the Group Header 80 Defining the sub-report 81 Defining the Details band 83 Defining the Group Footer and Page Footer 83 Incorporating the invoice report into your J2EE environment 84 Summary 86 Chapter 4: Design and Layout in Pentaho's Report Designer 87 Report Designer user interface components 87 Menu and toolbar 88 Report element palette 89 Report canvas tab panel 89 Report Explorer 89 Element Properties 89 Messages 90 Report bands 90 Common properties 90 Size and position properties 90 Padding and border properties 92 Page behavior properties 94 Foreground and background color properties 94 Excel properties 94 Attribute properties 95 Style inheritance 95 Page Header and Page Footer 95 Report Header and Report Footer 95 Group Header and Group Footer 96 Details Body 96 [ iii ]
  11. Table of Contents Watermark 96 Report elements 96 Common properties 97 Common text properties 97 Font style properties 98 Text style properties 98 Text spacing properties 99 Link properties 100 Excel properties 100 label 100 text-field 100 message 100 number-field 101 date-field 101 resource-label 102 resource-message 102 resource-field 102 chart 103 content (static image) 103 content-field (dynamic image) 103 rectangle 104 ellipse 104 horizontal-line and vertical-line 104 band 105 sub-report 105 survey-scale 105 line-sparkline 106 bar-sparkline 106 pie-sparkline 106 simple-barcodes 107 Visual layout in Report Designer 107 The Grid 108 Guide lines 108 Additional visual indicators 109 Moving and aligning single elements 110 Aligning groups of elements 110 Miscellaneous layout capabilities 111 Pentaho Report Designer shortcut keys 112 Working with fonts 113 Considerations for different output formats 114 Cell output 114 Paging 116 [ iv ]
  12. Table of Contents Limits to rich graphics and charts 116 Summary 116 Chapter 5: Working with Data Sources 117 Pentaho Reporting Engine Data API 117 The DataFactory interface 118 The ContextAwareDataFactory interface 119 The TableModel interface 119 DataFactory serialization 120 Additional data source metadata 121 Existing DataFactory implementations 121 TableDataFactory 121 NamedStaticDataFactory 122 Query syntax 122 NamedStaticDataFactory example 123 SQLReportDataFactory 125 StaticConnectionProvider 126 DriverConnectionProvider 126 JndiConnectionProvider 126 SQLReportDataFactory example 128 XPathDataFactory 129 XPathDataFactory example 131 HQLDataFactory 132 StaticSessionProvider 133 DefaultSessionProvider 133 HQLDataFactory Example 134 PmdDataFactory 137 XMI file 137 Domain Id 137 IPmdConnectionProvider 137 Registering MQL Queries 138 PmdDataFactory example 138 KettleDataFactory 143 KettleDataFactory example 145 BandedMDXDataFactory 148 BandedMDXDataFactory example 149 DenormalizedMDXDataFactory 152 CompoundDataFactory 153 Experimental data factories 153 Accessing data throughout a report 153 Summary 154 Chapter 6: Including Charts and Graphics in Reports 155 Supported charts 155 Common chart rendering properties 157 [v]
  13. Table of Contents Common category series rendering properties 159 Common XY series rendering properties 161 Common dataset properties 162 Common category series dataset properties 163 Common XY series dataset properties 163 Area chart 164 Area chart example 164 Bar chart 165 Bar chart example 166 Line chart 167 Line chart example 168 Pie chart 168 Pie chart example 170 Ring chart 171 Ring chart example 172 Multi pie chart 172 Multi pie chart example 173 Waterfall chart 173 Waterfall chart example 174 Bar line chart 174 Bar line chart example 175 Bubble chart 176 Bubble chart example 176 Scatter chart 177 Scatter chart example 178 XY Area, XY Bar and XY Line charts 178 XY charts example 179 Extended XY Line chart 179 Extended XY Line chart example 180 Radar chart 181 Radar chart example 181 Including static images in your report 182 Including dynamic images in your report 182 Summary 183 Chapter 7: Parameterization, Functions, Formulas, and Internationalization in Reports 185 Report parameterization 185 Providing report parameters 186 Available report parameter types 186 Working with functions and expressions 187 Common functions 188 Report functions 189 Summary functions 190 [ vi ]
  14. Table of Contents Running functions 192 Advanced functions 194 Image functions 196 Script functions 197 Working with formulas 198 Formula syntax 199 Formula data types 199 Formula operators 200 Formula functions 201 Date time functions 201 Logical functions 202 Mathematical functions 203 Text functions 204 Reporting Specific functions 206 Miscellaneous functions 206 Internationalization and localization of reports 207 Localizing fields 208 Localization example 209 Summary 210 Chapter 8: Adding Sub-Reports and Cross Tabs to Reports 211 Adding sub-reports 211 Multi-page sub-report example 212 Chart sub-report example 217 Side-by-side sub-report example 219 Adding cross tabs 221 Cross tab MDX example 222 Cross tab SQL example 228 Multiple row and column cross tab example 229 Summary 230 Chapter 9: Building Interactive Reports 231 Interactive reports in Swing 231 Registering event callbacks 231 ReportHyperlinkListener 231 ReportActionListener 232 ReportMouseListener 233 Interactive Swing example 234 Interactive reports in HTML 241 Interactive HTML report properties 241 Manipulating the reporting HTML DOM 243 Including an external CSS or JavaScript resource 243 Interactive HTML example 243 [ vii ]
  15. Table of Contents Adding interactive elements to the dashboard 247 Summary 250 Chapter 10: API-based Report Generation 251 Understanding the serialized report format 251 settings.xml 252 datadefinition.xml and the datasources folder 252 Parameters 252 Data source reference 254 Functions and expressions 254 Data sources folder 255 layout.xml 256 Group and detail band hierarchy 258 Report elements 258 Example layout.xml file 261 styles.xml 262 Example styles.xml file 263 Additional required files 264 Building and running a .prpt bundle example file 265 Building a report using Pentaho Reporting's Java API 266 Adding a data source 267 Defining parameters 267 Including functions and expressions 268 Defining the report's layout 269 Common report bands 269 Group band hierarchy 269 Adding elements to the report 270 Java API example 272 Wizard Java API 274 Summary 275 Chapter 11: Extending Pentaho Reporting 277 Implementing report functions and expressions 277 Implementing expressions 277 Defining an expression class 278 Defining expression metadata 278 An example expression 281 Implementing functions 287 Implementing a formula function 287 Regex formula function example 289 Implementing BeanShell expressions 292 Example BSHExpression 292 Implementing a report element 293 Defining an ElementType class 293 [ viii ]
  16. Table of Contents Defining element metadata 294 Defining read and write handlers 296 An example report element 296 Summary 305 Chapter 12: Additional Pentaho Reporting Topics 307 Using Pentaho Reporting with Pentaho's Business Intelligence Server 307 Downloading and Installing the BI Server 308 Publishing a report to the BI Server 309 Scheduling reports 311 Configuring permissions 313 Report emailing and bursting 313 Managing database connections and users 316 Creating ad hoc reports 318 Mobile reporting 319 Mobile report server 320 Mobile report design 321 Example: Pentaho's iPhone BI extension 321 Data source metadata in Pentaho Reporting 322 MetaTableModel API 323 Mapping external metadata 324 Using metadata attributes in a report 326 Current MetaTableModel implementations 327 Metadata example: DefaultMetaTableModel 328 Working with Pentaho Reporting's output layer 335 The OutputProcessorMetaData interface 335 The OutputProcessor interface 336 RenderNode Document Object Model 336 Updating Report Designer 337 Example: PojoObject output 337 The Pentaho community—getting help and contributing 343 Asking questions, helping others 343 Online documentation 343 Submitting bugs and viewing backlogs 343 Contributing code 344 Enterprise support 344 Summary 345 Index 347 [ ix ]
  17. Preface Pentaho Reporting lets you create, generate, and distribute rich and sophisticated report content from different data sources. Knowing how to use it quickly and efficiently gives you the edge in producing reports from your database. If you have been looking for a book that has plenty of easy-to-understand instructions and also contains lots of examples and screenshots, this is where your search ends. This book shows you how to replace or build your enterprise reporting solution from scratch with Pentaho's Reporting Suite. Through detailed examples, it dives deeply into all aspects of Pentaho's reporting functionalities, providing you with the knowledge you need to master report creation. What this book covers Chapter 1—An Introduction to Pentaho Reporting provides a quick overview of Pentaho Reporting, including a feature summary and architectural summary, as well as a history of the product. Chapter 2—Pentaho Reporting Client and Enterprise Examples tells how to install and create reports, and how to embed reports in your J2EE and client Java applications. Chapter 3— Pentaho Reporting Examples in the Real World tells how to connect to a JDBC data source and create realistic inventory, balance, and invoice reports, including charts and sub-reports. Chapter 4—Design and Layout in Pentaho's Report Designer takes a deep dive into Pentaho's Report Designer, learning how to create great-looking reports. Chapter 5—Working with Data Sources teaches the various ways to connect your report to live data, including JDBC, Hibernate, Java Beans, OLAP, and many other data sources.
  18. Preface Chapter 6—Including Charts and Graphics in Reports is about incorporating Pie, Bar, Line, and many other chart types in your reports, as well as including dynamic images in your report. Chapter 7—Parameterization, Functions, Formulas, and Internationalization in Reports defines parameters for dynamic report generation. It helps you write formulas and use available functions for rich summary and calculated values in your reports, along with dynamically adjusting colors and styles using expressions in your report. Chapter 8—Adding Sub-Reports and Cross Tabs to Reports gives an overview of how to build reports that include side-by-side sub-reports and cross tabs. Chapter 9—Building Interactive Reports teaches how to add dynamic interaction to HTML and Swing reports, for immediate feedback and dashboard-like functionality. Chapter 10—API-based Report Generation is about building reports from XML and by using Pentaho Reporting's Java Bean API. Chapter 11—Extending Pentaho Reporting teaches how to write custom functions and elements within Pentaho Reporting. Chapter 12—Additional Pentaho Reporting Topics discovers how to use Pentaho Reporting with the Pentaho BI Server, including Pentaho Metadata. It aids in learning more about Pentaho Reporting's open source approach, and how you can contribute to the free software movement. Who this book is for This book is primarily written for Java developers who want to assemble custom reporting solutions with Pentaho Reporting. Their main interest is in the technical details of creating reports. They want to see how to solve common report problems with a minimum of fuss and don't need an overview of BI or the importance of reporting. Secondary audiences of this book are information technologists who need to install a reporting solution in their environment, and want to learn advanced concepts within Pentaho Reporting such as sub-reports, cross tabs, data source configuration, and metadata-based reporting. [2]
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2