Monday 10 July 2017

Moving Average Jfreechart Beispiel


2009-08-06: freigabe von 0.6.0 wird veröffentlicht 2009-05-22: freigabe von 0.5.0 wird veröffentlicht 2009-03-16: freigabe von 0.5.0 beta. 2008-06-20: Release von 0.4.1, Neustart der Wiki-Seite und Einbindung der Foren als eingebettete Seiten: User Forum und Developers Forum. Genießen Sie 2008-05-04 Appendium Ltd und LavaBlast freuen sich, die Veröffentlichung der Version 0.4.0 von StatSVN bekannt zu geben. Weitere Details zu diesem Blog und dem Changelog. 2007-03-10 Nachrichten. Als Teil von Release 0.3.1 haben wir eine Reihe von Demos für einige bekannte Projekte gestartet: Subversion, Ant, Log4J, Spring Rich Client, Hibernate 3, Joda Time, Ruby, Groovy, Grails und Felix. Gehen Sie weiter, geben Sie zu, Sie wollten schon immer wissen, wer was und wann auf diesen Projekten gemacht hat. Warnung. Wenn Sie kein englisches Gebietsschema verwenden, setzen Sie die LANG-Umgebungsvariable auf enUS, wenn Sie die Anwendung ausführen, bis wir einige i18n-Probleme mit StatSVN lösen (der Aufruf von svn diff gibt eine lokalisierte Zeichenfolge zurück, die zu einigen Ergebnissen führen kann, die nicht zwischengespeichert werden Sind korrekt, aber StatSVN wird nächstes Mal nach ihnen fragen). 2007-02-07: Wollen Sie helfen, unsere Kommandozeilenaufrufe mit Anrufen an SVNKit (früher JavaSVN) zu ersetzen. Möchten Sie die Prototyp-Implementierung schreiben und sehen, wie gut es funktioniert Lass uns wissen, 2007-01-12: Version 0.3.0 ist in SVN und fügt 2 Berichte (RepoMap und LOCChurn) sowie die Festsetzung einer Reihe von Problemen mit bewegten Dateien, Verzeichnisse Und Streichung der. Weitere Details auf dieser Seite. 2006-11-28: Version 0.2.0 ist aus und unterstützt nun die Html - und XDoc-Generation, um die Integration mit Maven zu erleichtern (siehe hiermit). Wurden auch erfreut zu erwähnen, dass es ein Maven 2 Plugin mit StatSVN gibt, ist es bei stat-scm. sourceforge verfügbar. Tweet von den Autoren So, was ist StatSVN Große Statistiken für SVN StatSVN ruft Informationen aus einem Subversion Repository und generiert verschiedene Tabellen und Diagramme, die die Projektentwicklung beschreiben, z. B. Zeitleiste für die Zeilen des Zeugnisses Zeilen des Codes für jeden Entwickler Aktivität nach Uhrzeit Autoren Tätigkeit Autor Aktivität pro Modul Autor Die neuesten Commits mit Links zu ViewVc Stats pro Verzeichnis Dateizählung Durchschnittliche Dateigröße Größte Dateien Dateien mit den meisten Revisionen Verzeichnis Größen Repository Tags Anzahl der LOC pro Ausführung. Repository-Baum mit Dateizählung und Zeilen von Code LOC und Churn die Evolution von LOC und die Menge der Änderung pro Tag Repo Map die dynamische hierarchische Ansicht Ihres Repo für die letzten 30 Tage Die aktuelle Version von StatSVN generiert eine statische Suite von HTML-Dokumente mit Tabellen und Kartenbilder. StatSVN ist Open-Source-Software, veröffentlicht unter den Bedingungen der LGPL, basierend auf StatCVS. StatSVN nutzt JFreeChart, um Charts zu erzeugen. Wo ist das Handbuch Das Handbuch ist online als Wiki verfügbar und es ist so aktuell und umfassend wie es sein will. Schnelles Beispiel für Maven 1 Vor dem Ausführen von maven site (oder einfach maven xdoc) können Sie die XDOC-Dateien generieren, indem Sie: (nicht vergessen - v). Dieses Beispiel erzeugt xdoc im Verzeichnis sitestatsvn, Tag 0.2.0, 0.1.3, 0.1.2, 0.0.9, schließt qalab. xml und andere aus. Danach würde das XDOC von maven site oder maven xdoc abgeholt werden. Bitte beachten Sie, dass Sie, um die Tags zu verwenden, eine Protokolldatei nicht auf Trunk-Ebene verwenden müssen, sondern gerade oben, um das Tags-Verzeichnis einzufügen. Im Moment arbeitet StatSVN nur mit dem Tags-Verzeichnis. Schnell Beispiel für neue Dump Es gibt eine neue Dump-Anlage (nicht vergessen - v). Dies wird eine große Menge an Leistung generieren, aber am Ende dieses, wenn es OK für alles zeigt, ist es wahrscheinlich, dass StatSVN richtig verstanden Ihr Repository: JasperReports - Schnelle Anleitung JasperReports - Erste Schritte JasperReports - Umfeld Setup JasperReports - Lebenszyklus JasperReports - Designs JasperReports - Übersetzen von Berichtsentwurf JasperReports - Füllen von Berichten Jasper Report - Ansicht amp Drucken von Berichten JasperReports - Exportieren von Berichten Berichte Parameter Wenn auf java. lang. Boolean. TRUE gesetzt, wird der Bericht auf einer langen Seite generiert und Seitenumbruch wird nicht auftreten. Lassen Sie uns ReportTitle und Autor an den Bericht übergeben (erzeugt von JasperReportFill. java). Überarbeitete Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java ist wie folgt minus Der Inhalt der POJO-Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java sind wie unten minus Der Inhalt der Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java sind als Unten angegeben minus Lets add parameter die lt ReportTitle gt und lt Autor gt zu unserer bestehenden Reportvorlage (Kapitel Report Designs). Der Berichtstitel und der Autor werden zu Beginn des Berichts angezeigt. Die überarbeitete Berichtsvorlage (jasperreporttemplate. jrxml) lautet wie folgt. Speichern Sie es auf C: toolsjasperreports-5.0.1test Verzeichnis minus Reportgenerierung Wir werden die obige Datei mit unserem regulären ANT-Build-Prozess kompilieren und ausführen. Der Inhalt der Datei build. xml (gespeichert unter Verzeichnis C: toolsjasperreports-5.0.1test) ist wie unten. Die Importdatei - baseBuild. xml wird aus dem Kapitel Environment Setup ausgewählt und sollte im selben Verzeichnis wie die build. xml platziert werden. Als nächstes können Sie das Befehlszeilenfenster öffnen und in das Verzeichnis gehen, in dem build. xml platziert ist. Schließlich führen Sie den Befehl ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport ist das Standardziel) wie folgt minus Als Ergebnis der obigen Kompilierung öffnet sich ein JasperViewer-Fenster wie im folgenden Bildschirm gezeigt. Minus Hier sehen wir das ReportTitle Liste der Kontakte und Autor, die von Manisha vorbereitet werden, werden zu Beginn des Berichts angezeigt. Berichtsdatenquellen Datenquellen sind strukturierter Datencontainer. Während der Erstellung des Berichts erhält die JasperReports-Engine Daten aus den Datenquellen. Daten können aus den Datenbanken, XML-Dateien, Arrays von Objekten und Sammlung von Objekten gewonnen werden. Wir haben in dem Kapitel Füllen Berichte gesehen. Die fillReportXXX () - Methode erwartet, dass eine Datenquelle des Berichts, die füllen muss, in Form von net. sf. jasperreports. engine. JRDataSource-Objekt oder einer java. sql. Connection (wenn die Berichtsdaten in einem gefunden werden relationale Datenbank). Die JRDataSource-Schnittstelle hat nur zwei Methoden, die implementiert werden sollen minus public boolean next () throws JRException In der Report-Füllung wird diese Methode auf dem Datenquellenobjekt von der Reporting-Engine aufgerufen, wenn sie durch die Daten iteriert wird. Public Object getFieldValue (JRField jrField) wirft JRException Diese Methode liefert den Wert für jedes Berichtsfeld im aktuellen Datenquellendatensatz. Der einzige Weg, um Daten aus der Datenquelle abzurufen, ist die Verwendung der Berichtsfelder. Es gibt mehrere Standardimplementierungen der JRDataSource-Schnittstelle, je nach Art und Weise werden die Datensätze in der Datenquelle erfasst. Datasource Implementierungen Die untenstehende Tabelle fasst die Datenquellen und deren Implementierungsklassen ab Minus JDBC Data Sources Klasse JRResultSetDataSource schlägt ein java. sql. ResultSet Objekt. Dies ist die am häufigsten verwendete Datenquellenimplementierungen, wenn Berichtsdaten aus einer relationalen Datenbank extrahiert werden. Wenn eine java. sql. Connection an die Engine übergeben wird, führt sie zuerst die zugehörige Abfrage aus und speichert das zurückgegebene java. sql. ResultSet-Objekt in einer JRResultSetDataSource-Instanz. JavaBean Data Sources Klassen JRBeanArrayDataSource und JRBeanCollectionDataSource repräsentieren Implementierungen, die Arrays und Sammlungen von JavaBean Objekten verpacken können. Jedes Objekt innerhalb des Arrays oder der Auflistung wird als ein Datensatz in dieser Art von Datenquelle gesehen. Die Zuordnung zwischen einer bestimmten JavaBean-Eigenschaft und dem entsprechenden Berichtsfeld erfolgt durch Namenskonventionen. Der Name des Berichtsfeldes muss mit dem Namen der JavaBean-Eigenschaft übereinstimmen, wie sie in den JavaBeans-Spezifikationen angegeben ist. In allen Beispielen dieses Tutorials haben wir JRBeanCollectionDataSource verwendet. Kartenbasierte Datenquellen Die Implementierungsklassen JRMapArrayDataSource und JRMapCollectionDataSource sind nützlich, wenn die übergeordnete Anwendung bereits die im Speicher befindlichen Berichtsdaten als java. util. Map-Objekte speichert. Jedes Kartenobjekt in dem eingewickelten Array oder der Sammlung wird als virtueller Datensatz in der Datenquelle betrachtet, und der Wert jedes Berichtsfeldes wird aus der Karte mit dem Berichtsfeld, das als Schlüssel bezeichnet wird, extrahiert. TableModel-Datenquellen In vielen clientseitigen Anwendungen werden Daten tabellarisch dargestellt. Eine häufige Anforderung in vielen Anwendungen ist es, dass der Benutzer dieses tabellarische Format als Bericht drucken kann. Implementierungsklasse JRTableModelDataSource macht die Aufgabe, Berichte aus tabellarischem Format für Swing-Anwendungen trivial zu generieren. Diese Klasse wickelt ein javax. swing. table. TableModel-Objekt. Spalten in dem eingepackten TableModel-Objekt können entweder durch ihre Namen oder durch ihre 0-basierten Indizes zugegriffen werden. XML-Datenquellen Klasse JRXmlDataSource ist eine auf DOM basierende Datenquellenimplementierung, die XPath-Ausdrücke verwendet, um Daten aus dem XML-Dokument auszuwählen. Aufzeichnungen in der XML-Datenquelle werden durch Knotenelemente dargestellt, die durch den XPath-Ausdruck ausgewählt wurden. Feldwerte werden aus jedem Datensatz mit dem XPath-Ausdruck abgerufen, der durch die Feldbeschreibung (ltfieldDescriptiongt-Element in JRXML) bereitgestellt wird. XPath ist eine Sprache, die verwendet wird, um durch XML-Dokumente Attribute und Elemente zu navigieren. Weitere Informationen über XPath finden Sie unter w3.orgTRxpath. CSV-Datenquellen JRCsvDataSource stellt eine Implementierung für Datenquellen dar, die ihre Daten aus strukturierten Textdateien in der Regel CSVs abrufen. Feldwerte werden mit ihrem Spaltenindex abgerufen. XLS-Datenquellen JRXlsDataSource stellt eine Implementierung für Datenquellen dar, die ihre Daten aus Excel-Dokumenten abrufen. Die Berichtsfeldzuordnung für diese Datenquellenimplementierung basiert ebenfalls auf dem Feldspaltenindex. Leere Datenquellen Die Klasse JREmptyDataSource. Simuliert eine Datenquelle mit einer bestimmten Anzahl von virtuellen leeren Datensätzen im Inneren. Es wird von den UI-Tools verwendet, um grundlegende Berichtsvorschau-Funktionalität oder spezielle Berichtsvorlagen oder zum Testen und Debuggen anzubieten. Rückspulbare Datenquellen Die net. sf. jasperreports. engine. JRRewindableDataSource erweitert die grundlegende JRDataSource-Schnittstelle. Es fügt nur eine Methode, genannt moveFirst (), an die Schnittstelle. Diese Methode soll den Cursor auf das erste Element in der Datenquelle verschieben. Rückspulbare Datenquellen sind nützlich, wenn Sie mit Unterprotokollen arbeiten, die in einem Band platziert sind, das aufgrund der isSplitAllowedfalse-Einstellung nicht aufgeteilt werden darf und auf der aktuellen Seite nicht genügend Speicherplatz für den zu übergebenden Teilbericht vorhanden ist. Alle oben genannten Datenquellenimplementierungen sind mit Ausnahme der JRResultSetDataSource rückverfolgbar. Da es nicht unterstützt, den Datensatzzeiger zurück zu bewegen. Dies stellt nur dann ein Problem dar, wenn diese Datenquelle manuell verwendet wird, um ein java. sql. ResultSet zu verpacken, bevor es an den Unterbericht übergeben wird. Es gibt kein Problem, wenn sich die SQL-Abfrage in der Unterberichtvorlage befindet, da die Engine sie beim Neustart des Unterberichtes auf der nächsten Seite erneut ausführt. Datenquellenanbieter Die JasperReports-Bibliothek verfügt über eine Schnittstelle net. sf. jasperreports. engine. JRDataSourceProvider. Dies hilft bei der Erstellung und Entsorgung von Datenquellenobjekten. Beim Erstellen einer Berichtsvorlage mit GUI-Tools ist ein spezielles Werkzeug zum Anpassen der Berichtsdatenquelle erforderlich. JRDataSourceProvider ist die Standardmethode, um benutzerdefinierte Datenquellen in ein Design-Tool zu stecken. Eine benutzerdefinierte Implementierung dieser Schnittstelle sollte die folgenden Methoden implementieren, die das Erstellen und Entsorgen von Datenquellenobjekten und auch Methoden zur Auflistung der verfügbaren Berichtsfelder innerhalb der Datenquelle ermöglichen, wenn möglich abzüglich Berichtsfelder Berichtsfelder sind Elemente, die die Zuordnung von Daten zwischen der Datenquelle darstellen Und Berichtsvorlage. Felder können in den Berichtsausdrücken kombiniert werden, um die gewünschte Ausgabe zu erhalten. Eine Berichtsvorlage kann null oder mehr ltfieldgt-Elemente enthalten. Bei der Deklaration von Berichtsfeldern sollte die Datenquelle Daten liefern, die allen in der Berichtsvorlage definierten Feldern entsprechen. Felddeklaration Felddeklaration erfolgt wie unten gezeigt minus Das Namensattribut Das Namensattribut des ltfieldgt-Elements ist obligatorisch. Es verweist auf das Feld in Berichtsausdrücken nach Namen. Das Klassenattribut Das Klassenattribut gibt den Klassennamen für die Feldwerte an. Der Standardwert ist java. lang. String. Dies kann in jede zur Laufzeit verfügbare Klasse geändert werden. Unabhängig von der Art eines Berichtsfeldes kümmert sich der Motor um das Gießen in die Berichtsausdrücke, in denen das F-Token verwendet wird, so dass manuelle Abgüsse unnötig werden. Feld Beschreibung Das Element ltfieldDesciptiongt ist ein optionales Element. Dies ist bei der Implementierung einer benutzerdefinierten Datenquelle sehr nützlich. Zum Beispiel können wir einen Schlüssel oder einige Informationen speichern, mit denen wir den Wert des Feldes aus der benutzerdefinierten Datenquelle zur Laufzeit abrufen können. Durch die Verwendung des ltfieldDesciptiongt-Elements anstelle des Feldnamens können Sie bei der Abfrage der Feldwerte aus der Datenquelle die Beschränkungen von Feldnamenskonventionen leicht überwinden. Im Folgenden ist ein Stück Code aus unserer bestehenden JRXML-Datei (Kapitel Report Designs). Hier sehen wir den Namen des Namens. Klasse. Und fieldDescription Elemente. Sortierfelder Zu den Zeiten, in denen die Datensortierung erforderlich ist und die Datenquellenimplementierung dies nicht unterstützt (z. B. CSV-Datenquelle), unterstützt JasperReports die in-Memory-Feld-basierte Datenquellensortierung. Die Sortierung kann mit einem oder mehreren ltsortFieldgt-Elementen in der Berichtsvorlage durchgeführt werden. Wenn mindestens ein Sortierfeld angegeben ist, wird während des Berichtsabfüllvorgangs die Datenquelle an eine JRSortableDataSource-Instanz übergeben. Dies wiederum holt alle Datensätze aus der Datenquelle, führt die Speichersortierung nach den angegebenen Feldern durch und ersetzt die ursprüngliche Datenquelle. Der Sortierfeldname sollte mit dem Berichtsfeldnamen identisch sein. Felder, die für die Sortierung verwendet werden, sollten Typen haben, die java. utilparable implementieren. Die Sortierung der Natural Order erfolgt für alle Felder außer denen des Typs java. lang. String (für String-Typ, Collator, der dem Report-Fill-Gebietsschema entspricht). Wenn mehrere Sortierfelder angegeben sind, wird die Sortierung mit den Feldern als Sortierschlüssel in der Reihenfolge durchgeführt, in der sie in der Berichtsvorlage erscheinen. Das folgende Beispiel zeigt die Sortierfunktion. Sortiertes Berichtsbeispiel Lässt das lt sortField gt Element zu unserer bestehenden Berichtsvorlage hinzufügen (Kapitel Berichtsentwürfe). Lässt das Feld in absteigender Reihenfolge sortieren. Die überarbeitete Berichtsvorlage (jasperreporttemplate. jrxml) lautet wie folgt. Speichern Sie es auf C: toolsjasperreports-5.0.1test Verzeichnis minus Die Java-Codes für die Berichtsfüllung bleiben unverändert. Der Inhalt der Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java sind wie unten angegeben minus Der Inhalt der POJO-Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java sind wie unten angegeben minus Der Inhalt der Datei C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java sind wie unten angegeben minus Reportgenerierung Wir werden die obige Datei mit unserem regulären ANT-Build-Prozess kompilieren und ausführen. Der Inhalt der Datei build. xml (gespeichert unter Verzeichnis C: toolsjasperreports-5.0.1test) sind wie unten angegeben. Die Importdatei - baseBuild. xml wird aus dem Kapitel Environment Setup ausgewählt und sollte im selben Verzeichnis wie die build. xml platziert werden. Als nächstes können Sie das Befehlszeilenfenster öffnen und in das Verzeichnis gehen, in dem build. xml platziert ist. Schließlich führen Sie den Befehl ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport ist das Standardziel) wie folgt minus Als Ergebnis der obigen Kompilierung öffnet sich ein JasperViewer-Fenster wie in dem unten aufgeführten Bildschirm angezeigt. Minus Hier sehen wir das Die Ländernamen sind in absteigender Reihenfolge alphabetisch angeordnet. Berichtsausdruck Berichtsausdrücke sind die leistungsstarken Funktionen von JasperReports, die es uns erlauben, berechnete Daten in einem Bericht anzuzeigen. Berechnete Daten sind die Daten, die keine statischen Daten sind und nicht spezifisch als Berichtsparameter oder Datenquellenfeld übergeben werden. Berichtsausdrücke werden aus der Kombination von Berichtsparametern, Feldern und statischen Daten erstellt. Die Java-Sprache wird standardmäßig zum Schreiben von Berichtsausdrücken verwendet. Andere Skriptsprachen für Berichtsausdrücke wie Groovy Skriptsprache, JavaScript oder BeanShell-Skript werden von JasperReports Compilern unterstützt. Dieses Kapitel erklärt Ihnen, abgesehen davon, wie Berichtsausdrücke funktionieren, vorausgesetzt, dass sie nur mit der Java-Sprache geschrieben wurden. In einer JRXML-Berichtsvorlage gibt es mehrere Elemente, die Ausdrücke definieren als minus ltvariableExpressiongt ltinitialValueExpressiongt ltgroupExpressiongt ltprintWhenExpressiongt ltimageExpressiongt lttextFieldExpressiongt Expressionsdeklaration Grundsätzlich sind alle Berichtsausdrücke Java-Ausdrücke, die auf die Berichtsfelder, Berichtsvariablen und Berichtsparameter verweisen können. Feldreferenz in Ausdruck Um eine Berichtsfeldreferenz in einem Ausdruck zu verwenden, muss der Name des Feldes zwischen F und Zeichenfolgen gesetzt werden, wie unten gezeigt. Minus Nachfolgend ist ein Stück Code aus unserer vorhandenen JRXML-Datei (Kapitel Berichtsentwürfe) abzüglich Variable Referenz in Ausdruck Um eine Variable in einem Ausdruck zu verweisen, müssen wir den Namen der Variablen zwischen V und wie in dem unten angegebenen Beispiel gezeigt haben. Minus Parameterreferenz in Ausdruck Um einen Parameter in einem Ausdruck zu verweisen, sollte der Name des Parameters gesetzt werden Zwischen P und wie in dem unten angegebenen Beispiel gezeigt minus Nachfolgend ist ein Stück Code aus unserer vorhandenen JRXML-Datei, die die Referenzierung des Parameters in einem Ausdruck demonstriert. (JRXML aus Kapitel Berichtsentwürfe) minus Wie Sie oben gesehen haben, sind die Parameter-, Feld - und Variablenreferenzen tatsächlich echte Java-Objekte. Wenn wir ihre Klasse aus der in der Berichtsvorlage vorgenommenen Parameter-, Feld - oder Variablendeklaration kennen, können wir auch Methoden zu den Objektreferenzen in den Ausdrücken aufrufen. Das folgende Beispiel zeigt minus, wie man den ersten Buchstaben aus dem java. lang. String-Berichtsfeld extrahiert und anzeigt. Name Minus Resource Bundle Referenz in Ausdruck Um eine Ressource in einem Ausdruck zu verweisen, sollte der Schlüssel zwischen R und wie in dem angegebenen Beispiel gezeigt werden Unten minus Basierend auf dem Laufzeit-bereitgestellten Gebietsschema und dem report. title-Schlüssel wird das mit der Berichtsvorlage verknüpfte Ressourcenbündel geladen. Daher wird der Titel des Berichts angezeigt, indem der String-Wert aus dem Ressourcenbündel extrahiert wird. Mehr zur Internationalisierung finden Sie im Kapitel Internationalisierung. Calculator Calculator ist eine Entität in JasperReports, die Ausdrücke auswertet und Variablen oder Datensätze in Berichtszeit füllt. Während des Kompilierungsprozesses werden die Informationen erstellt und im Compilerbericht vom Compiler gespeichert. Diese Informationen werden während der Berichtszeit verwendet, um eine Instanz der net. sf. jasperreports. engine. fill. JRCalculator-Klasse zu erstellen. Java-Quelldatei wird von Java-basierten Report-Compilern erstellt und kompiliert. Diese generierte Klasse ist eine Unterklasse des JRCalculator, und der Bytecode, der durch Kompilieren erzeugt wird, wird im JasperReport-Objekt gespeichert. Dieser Bytcode wird in der Berichtsabfüllzeit geladen und die resultierende Klasse wird instanziiert, um das Berechnungsobjekt zu erhalten, das für die Ausdrucksauswertung benötigt wird. Bedingte Ausdrücke JasperReports unterstützt keine if-else-Anweisungen bei der Definition von Variablenausdrücken. Stattdessen können Sie die ternären Operatoren verwenden. . . Dieser Operator kann in einem Java-Ausdruck verschachtelt werden, um die gewünschte Ausgabe basierend auf mehreren Bedingungen zu erhalten. Beispiel für bedingte Ausdrücke im Bericht Lässt die vorhandene Berichtsvorlage (Kapitel Berichtsentwürfe) ändern und einen bedingten Ausdruck für das Feldland hinzufügen. Die überarbeitete Berichtsvorlage (jasperreporttemplate. jrxml) lautet wie folgt. Speichern Sie es auf C: toolsjasperreports-5.0.1test Verzeichnis minus Die Java-Codes für die Berichterstattung sind wie folgt. Der Inhalt der Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java sind als minus Der Inhalt der POJO-Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java sind als minus Wir werden einen neuen Datensatz mit Länderfeld als leer in unserer Java-Bean hinzufügen Liste. Der Inhalt der Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java sind als minus Reportgenerierung Wir werden die obige Datei mit unserem regulären ANT-Build-Prozess kompilieren und ausführen. Der Inhalt der Datei build. xml (gespeichert unter Verzeichnis C: toolsjasperreports-5.0.1test) sind unten angegeben. Die Importdatei - baseBuild. xml wird aus dem Kapitel Environment Setup ausgewählt und sollte im selben Verzeichnis wie die build. xml platziert werden. Als nächstes können Sie das Befehlszeilenfenster öffnen und in das Verzeichnis gehen, in dem build. xml platziert ist. Schließlich führen Sie den Befehl ant - Dmain-class com. tutorialspoint. JasperReportFill (viewFullReport ist das Standardziel) als Minus Als Ergebnis der oben genannten Kompilierung öffnet sich ein JasperViewer-Fenster wie in dem unten aufgeführten Bildschirm angezeigt. Minus Hier können wir sehen, Für den letzten Rekord hatten wir keine Daten für das Feldland bestanden, es wird kein LAND gedruckt. Berichtsvariablen Berichtsvariablen sind spezielle Objekte, die auf dem Berichtsausdruck erstellt wurden. Berichtsvariablen vereinfachen die folgenden Aufgaben ab minus Berichtsausdrücke, die während der gesamten Berichtsvorlage stark verwendet werden. Diese Ausdrücke können nur einmal mit den Reportvariablen deklariert werden. Berichtsvariablen können verschiedene Berechnungen auf der Grundlage der entsprechenden Ausdrücke Werte wie Zählung, Summe, Durchschnitt, niedrigste, höchste, Varianz usw. durchführen. Wenn Variablen in einem Berichtsentwurf definiert sind, können diese durch neue Variablen in den Ausdrücken referenziert werden. Daher ist die Reihenfolge, in der die Variablen in einem Berichtsentwurf deklariert werden, wichtig. Variable Deklaration Eine Variablendeklaration ist wie folgt minus Wie oben gesehen, enthält das Element ltvariablegt die Anzahl der Attribute. Diese Attribute sind unten zusammengefasst minus Das Namensattribut Ähnlich wie Parameter und Felder. Das Namensattribut des ltvariablegt-Elements ist obligatorisch. Es erlaubt die Referenzierung der Variablen durch ihren deklarierten Namen in den Berichtsausdrücken. Das Klassenattribut Das Klassenattribut ist auch obligatorisch, das den Klassennamen für die Variablenwerte angibt. Der Standardwert ist java. lang. String. Dies kann in jede beliebige Klasse im Klassenpfad geändert werden, sowohl bei der Berichtszusammenstellungszeit als auch bei der Berichtszeit. Der Motor kümmert sich um das Typgießen in Berichtsausdrücken, die das V-Token verwendet, daher ist ein manuelles Gießen nicht erforderlich. Berechnung Dieses Attribut bestimmt abzüglich der Berechnung, die bei der Befüllung des Reports auf der Variablen durchgeführt werden soll. Die folgenden Unterabschnitte beschreiben alle möglichen Werte für das Berechnungsattribut des ltvariablegt-Elements. Durchschnittlicher Minus Der Variablenwert ist der Durchschnitt jedes Nicht-Nullwertes des Variablenausdrucks. Nur für numerische Variablen gültig. Count minus Der Variablenwert ist die Anzahl der Nicht-Null-Instanzen des Variablenausdrucks. First minus Der Variablenwert ist der Wert der ersten Instanz des Variablenausdrucks. Folgende Werte werden ignoriert. Höchster Minus Der Variablenwert ist der höchste Wert für den Variablenausdruck. Niedrigster Minus Der Variablenwert ist der niedrigste Wert für den Variablenausdruck im Bericht. Nichts minus Es werden keine Berechnungen an der Variablen durchgeführt. StandardDeviation minus Der Variablenwert ist die Standardabweichung aller Nicht-Nullwerte, die dem Berichtsausdruck entsprechen. Nur für numerische Variablen gültig. Summinus Der Variablenwert ist die Summe aller Nicht-Null-Werte, die vom Berichtsausdruck zurückgegeben werden. System minus Der Variablenwert ist eine benutzerdefinierte Berechnung (Berechnung des Wertes für diese Variable selbst, mit der Scriptlets Funktionalität von JasperReports). Variance minus Der Variablenwert ist die Varianz aller Nicht-Null-Werte, die durch die Auswertung des Reportvariablenausdrucks zurückgegeben werden. Incrementer FactoryClass Dieses Attribut bestimmt die Klasse, die verwendet wird, um den Wert der Variablen zu berechnen, wenn der aktuelle Datensatz im Bericht ausgefüllt wird. Der Standardwert wäre eine beliebige Klasse, die net. sf. jasperreports. engine. fill. JRIncrementerFactory implementiert. Die Fabrikklasse wird von der Engine verwendet, um Inkrementerobjekte zur Laufzeit zu instanziieren, abhängig vom Berechnungsattribut, das für die Variable gesetzt ist. IncrementType Hier legen Sie fest, wann der Wert der Variablen neu berechnet werden soll. Dieses Attribut verwendet Werte, wie unten minus Spalte minus Der Variablenwert wird am Ende jeder Spalte neu berechnet. Group minus Der Variablenwert wird neu berechnet, wenn sich die von incrementGroup angegebene Gruppe ändert. Keine minus Der Variablenwert wird mit jedem Datensatz neu berechnet. Seite minus Der Variablenwert wird am Ende jeder Seite neu berechnet. Report minus Der Variablenwert wird einmal am Ende des Berichts neu berechnet. IncrementGroup Hiermit wird der Name der Gruppe festgelegt, bei der der Variablenwert neu berechnet wird, wenn incrementType Gruppe ist. Hierbei handelt es sich um eine in der JRXML-Berichtsvorlage deklarierte Gruppe. Dies bestimmt, wann der Wert einer Variablen zurückgesetzt wird. Dieses Attribut verwendet Werte, wie unten minus Spalte minus Der Variablenwert wird am Anfang jeder Spalte zurückgesetzt. Gruppe minus Der Variablenwert wird zurückgesetzt, wenn sich die von incrementGroup angegebene Gruppe ändert. Keine minus Der Variablenwert wird niemals zurückgesetzt. Seite minus Der Variablenwert wird am Anfang jeder Seite zurückgesetzt. Report minus Der Variablenwert wird nur einmal am Anfang des Berichts zurückgesetzt. ResetGroup Hiermit wird der Name der Gruppe festgelegt, bei der der Variablenwert zurückgesetzt wird, wenn resetType Gruppe ist. Die Werte für dieses Attribut wären der Name einer Gruppe, die in der JRXML-Berichtsvorlage deklariert wurde. Eingebaute Reportvariablen Es gibt einige eingebaute Systemvariablen, die in Ausdrücken verwendet werden können, wie folgt minus Variablenname und Beschreibung Dieser Variablenwert ist seine aktuelle Seitennummer. Es kann verwendet werden, um sowohl die aktuelle Seitenzahl als auch die Gesamtzahl der Seiten mit einer Besonderheit von JasperReports-Textfeld-Elementen, dem Attribut outputTime anzuzeigen. Der Name dieser Variablen wird aus dem Namen der Gruppe abgeleitet, die mit der COUNT-Sequenz versehen ist. Diese Variable enthält die Anzahl der Datensätze in der aktuellen Gruppe. Fügen Sie eine Variable (countNumber) zu unserer vorhandenen Berichtsvorlage hinzu (Kapitel Report Designs). Wir werden die Zählung auf jeden Datensatz voranstellen. Die überarbeitete Berichtsvorlage (jasperreporttemplate. jrxml) lautet wie folgt. Speichern Sie es auf C: toolsjasperreports-5.0.1test Verzeichnis minus Die Java-Codes für die Berichtsfüllung bleiben unverändert. Der Inhalt der Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java sind wie unten angegeben minus Der Inhalt der POJO-Datei C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java sind wie unten angegeben minus Der Inhalt der Datei C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java sind wie unten angegeben minus Report Generation Wir werden kompilieren und führen Sie die oben genannten Datei mit unserem regulären ANT Build-Prozess. Der Inhalt der Datei build. xml (gespeichert unter Verzeichnis C: toolsjasperreports-5.0.1test) sind wie unten angegeben. Die Importdatei - baseBuild. xml wird aus dem Kapitel Environment Setup ausgewählt und sollte im selben Verzeichnis wie die build. xml platziert werden. Als nächstes können Sie das Befehlszeilenfenster öffnen und in das Verzeichnis gehen, in dem build. xml platziert ist. Schließlich führen Sie den Befehl ant - Dmain-classcom. tutorialspoint. JasperReportFill aus (viewFullReport ist das Standardziel) als Minus Als Ergebnis der obigen Kompilierung öffnet sich ein JasperViewer-Fenster wie auf dem Bildschirm unten minus Hier sehen wir, dass die Zählung vorangestellt ist Für jeden Datensatz Berichtsabschnitte Wir haben die Struktur einer einfachen Berichtsvorlage im Kapitel Getting Started besprochen. In ähnlicher Weise strukturiert JasperReports die Berichtsvorlage in mehrere Abschnitte. Abschnitte sind Teile des Berichts, die eine bestimmte Höhe haben und Berichtsobjekte wie Zeilen, Rechtecke, Bilder oder Textfelder enthalten können. Der Report-Engine iteriert durch die virtuellen Datensätze der bereitgestellten Berichtsdatenquelle, zum Zeitpunkt der Berichtszeit. Abhängig von den einzelnen Abschnitten definiert das Verhalten, dann macht der Motor dann jeden Bericht Abschnitt, wenn angemessen. Zum Beispiel wird der Detailabschnitt für jeden Datensatz in der Datenquelle gerendert. Wenn Seitenumbrüche auftreten, werden die Seitenkopf - und Seitenfußabschnitte nach Bedarf gerendert. In JasperReports werden Terminologie - und Reportabschnitte auch als Berichtsbänder bezeichnet. Die Abschnitte bestehen aus einer oder mehreren Bändern. Diese Abschnitte werden bei der Berichterstellungszeit wiederholt ausgefüllt und das endgültige Dokument vorbereitet. Hauptabschnitte Eine Berichtsvorlage in JasperReports hat die folgenden Hauptabschnitte ab Minus Die folgende Tabelle fasst jeden der Abschnitte ab Minus Höhe des Abschnitts gibt die Höhe in Pixeln für diesen bestimmten Abschnitt an und ist im Gesamtberichtdesign sehr wichtig. Drucken bei Ausdruck Ein boolescher Ausdruck, der bestimmt, ob der Abschnitt gedruckt werden soll oder nicht. Split erlaubt Ein Flag, das angibt, ob der Abschnitt aufgeteilt werden darf, wenn er nicht auf die aktuelle Seite passt. Wenn wahr, wird der Abschnitt auf die nächste Seite übertragen. Beachten Sie, dass im Fall, dass der Abschnitt nicht auf die nächste Seite passt, wird der Abschnitt unabhängig vom Flags-Wert aufgeteilt. SplitType kann folgende Werte minus splitTypeStretch: Splits gestreckten Inhalt. Wenn sich der Abschnitt auf der aktuellen Seite ausdehnt (wenn der verfügbare Platz kleiner als deklariert ist), darf die Region, die der ursprünglichen Höhe hinzugefügt wird, auf die nächste Seite aufgeteilt werden. SplitTypePrevent: Vermeidung von Split beim ersten Versuch. Wenn der Abschnitt nicht auf die nächste Seite passt, tritt der Split normal auf, da die Bandspaltverhinderung nur beim ersten Split-Versuch wirksam ist. SplitTypeImmediate: sofort teilen. Die Band darf sich irgendwo außer oben teilen, ihr oberstes Element. Um jeden Abschnitt zu demonstrieren, schreibe ich Reportvorlage (jasperreporttemplate. jrxml). Speichern Sie diese Datei in das Verzeichnis C: toolsjasperreports-5.0.1test. In dieser Datei würden wir einen Text in jedem der Abschnitte anzeigen (wir haben oben diskutiert). Der Inhalt der Datei ist wie unten angegeben minus Der Java-Code zu füllen und generieren den Bericht ist unten gegeben. Lets speichern diese Datei JasperReportFill. java zu C: toolsjasperreports-5.0.1testsrccomtutorialspoint Verzeichnis. Hier verwenden wir eine Instanz von JREmptyDataSource beim Abfüllen von Berichten, um eine Datenquelle mit einem Datensatz zu simulieren, aber mit allen Feldern in diesem Einzelsatz ist null. Berichtsgenerierung Wir werden die obige Datei mit unserem regulären ANT-Build-Prozess kompilieren und ausführen. Der Inhalt der Datei build. xml (gespeichert unter Verzeichnis C: toolsjasperreports-5.0.1test) ist wie unten. Die Importdatei - baseBuild. xml wird aus dem Kapitel Environment Setup abgeholt und sollte im selben Verzeichnis wie die build. xml platziert werden. Als nächstes können Sie das Befehlszeilenfenster öffnen und in das Verzeichnis gehen, in dem build. xml platziert ist. Schließlich führen Sie den Befehl ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport ist das Standardziel) wie folgt minus Als Ergebnis der obigen Kompilierung öffnet sich ein JasperViewer-Fenster wie auf dem Bildschirm unten minus Hier sehen wir in jedem von the sections a text is printed. It is to be noted that as JRXML contains a ltlastPageFootergt element, it will be displayed in the last page of the report instead of the ltpageFootergt element being displayed. The ltcolumnHeadergt and ltcolumnFootergt elements will only be displayed on the report, if it has more than one column. Report Groups Groups in JasperReports help to organize data on report in a logical manner. A report group represents a sequence of consecutive records in the data source, which have something in common, such as the value of a certain report fields. A report group is defined by the ltgroupgt element. A report can have any number of groups. Once declared, groups can be referred throughout the report. A report group has three elements minus Group expression minus This indicates the data that must change to start a new data group. Group header section minus Helps place label at the beginning of the grouped data. Group footer section minus Helps place label at the end of the grouped data. During the iteration through the data source at report-filling time if the value of the group expression changes, a group rupture occurs and the corresponding ltgroupFootergt and ltgroupHeadergt sections are inserted in the resulting document. Report group mechanism does not perform any sorting on the data supplied by the data source. Data grouping works as expected only when the records in the data source are already ordered according to the group expressions used in the report. Group Attributes The ltgroupgt element contains attributes that allow us to control how grouped data is laid out. The attributes are summarized in table below minus Attribute and Description This is mandatory. It references the group in report expressions by name. It follows the same naming conventions that we mentioned for the report parameters, fields, and report variables. It can be used in other JRXML attributes when you want to refer a particular report group. When set to true . each data group will begin on a new column. Default value is false . When set to true . prevents the group from splitting on its first break attempt. Lets add a group ( CountryGroup ) to existing report template (Chapter Report Designs ). Occurrence of each country is counted and the count is displayed as the group footer. In the group header, the count of each record is prefixed. The revised report template (jasperreporttemplate. jrxml) is as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The java codes for report filling remains unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as given below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as below. The import file - baseBuild. xml is picked up from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as in the screen below minus Here, we see that the each country is grouped and the count of occurrence of each country is displayed at the footer of each group. Report Fonts A report contains text elements and each of these can have its own font settings. These settings can be specified using the lt font gt tag available in the lttextElementgt tag. A report can define a number of fonts. Once defined, they can be used as default or base font settings for other font definitions throughout the entire report. Report Fonts A report font is a collection of font settings, declared at the report level. A report font can be reused throughout the entire report template when setting the font properties of text elements. Report fonts are now deprecated. Do not use ltreportFontgt elements declared within the document itself. Use the ltstylegt element instead. Font Attributes Table below summarizes the main attributes of the lt font gt element minus The flag that specifies whether the font should be embedded into the document itself. It defaults to false. If set to true, helps view the PDF document without any problem. Font Types In JasperReports fonts can be categorized as minus Logical Fonts minus Five font types, which have been recognized by the Java platform since version 1.0, are called logical fonts. These are minus Serif, SansSerif, Monospaced, Dialog, and DialogInput . These logical fonts are not actual font libraries that are installed anywhere on the system. They are merely font type names recognized by the Java runtime. These must be mapped to some physical font that is installed on the system. Physical Fonts minus These fonts are the actual font libraries consisting of, for example, TrueType or PostScript Type 1 fonts. The physical fonts may be Arial, Time, Helvetica, Courier, or any number of other fonts, including international fonts. Font Extensions minus The JasperReports library can make use of fonts registered on-the-fly at runtime, through its built-in support for font extensions. A list of font families can be made available to the JasperReports using font extension. These are made out of similarly looking font faces and supporting specific locales. As described in the table above we need to specify in the attribute fontName the name of a physical font, the name of a logical font, or the name of a font family from the registered JasperReports font extensions. PDF Font Name JasperReports library uses the iText library, when exporting reports to PDF(Portable Document Format). PDF files can be viewed on various platforms and will always look the same. This is partially because in this format, there is a special way of dealing with fonts. fontName attribute is of no use when exporting to PDF. Attribute pdfFontName exist where we need to specify the font settings. The iText library knows how to deal with built-in fonts and TTF files and recognizes the following built-in font names minus Courier Courier-Bold Courier-BoldOblique Courier-Oblique Helvetica Helvetica-Bold Helvetica-BoldOblique Helvetica-Oblique Symbol Times-Roman Times-Bold Times-BoldItalic Times-Italic ZapfDingbats As per iText library pre-requisite, to work with fonts, we need to specify one of the following as the font name minus A built-in font name from the above list. The name of a TTF (True Type Font) file, which it can locate on disk. The real name of the font, provided that the TTF file containing the font has been previously registered with iText or that an alias was defined when the font was registered. Based on the above pre-requisites, the pdfFontName attribute can contain one of the following values minus The name of a built-in PDF font from the above list. The name of a TTF file that can be located on disk at runtime when exporting to PDF. The real name of a registered font. The suffix of the key (the part after net. sf. jasperreports. export. pdf. font ) for a font registered with iText as a font file. Default Fonts and Inheritance Each text element inherits font and style attributes from its parent element, which in turn inherits these attributes from its parent. If no styles andor fonts are defined for elements, the default style (andor font - but this is now deprecated) declared in the ltjasperReportgt root element will be applied. Defining default styles or fonts in JasperReports is not mandatory. If no font is defined for a given element, the engine looks either for the inherited font attributes, or, if no attributes are found on this way, it looks for the net. sf. jasperreports. default. font. name property in the srcdefault. jasperreports. properties file. Its value defines the name of the font family to be used when font properties are not explicitly defined for a text element or inherited from its parent. The main default font properties and their values defined in the srcdefault. jasperreports. properties file are in the table below minus By default PDF fonts are not embedded. To demonstrate using fonts and font attributes in order to get a particular text appearance, lets write new report template (jasperreporttemplate. jrxml). The contents of the JRXML are as below. Save it to C:toolsjasperreports-5.0.1test directory. Here, we will display a text in the title of the report in various font formats. The java code to fill and generate the report is as given below. Lets save this file JasperFontsReportFill. java to C:toolsjasperreports-5.0.1testsrccomtutorialspoint directory. Here, we use an instance of JREmptyDataSource when filling reports to simulate a data source with one record in it, but with all the fields being null . Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperFontsReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the text Welcome to TutorialsPoint is displayed in different font formats. Unicode Support In JasperReports, working with texts needs some dedicated tools to process both the character representations and the text formatting properties. Any text can be considered as a character sequence with a particular representation structure. The text appearance consists in both layout (and paragraph) and font settings. But while in most cases, the text layout remains invariant, font settings may change when running the report in different Locales. We know that different languages need different character sets with respect to specific characters representation. Therefore, working with texts means working with fonts. However, a detailed discussion about how to use fonts in JasperReports is available in the chapter Report Fonts . One of the main features concerning the text content in a given report is the possibility to internationalize it. It means, we can run the report in different localized environments, using different languages and other localization settings without any hardcoded modification. Character encoding is an important feature when a report is intended to be internationalized. Character Encoding A character is the smallest unit of writing conveying a meaningful information. It is an abstract concept, a character does not have a visual appearance. Uppercase Latin A is a different character from lowercase Latin a and from uppercase Cyrillic A and uppercase Greek Alpha. A visual representation of a character is known as a glyph . A certain set of glyphs is called a font . Uppercase Latin A, uppercase Cyrillic A and uppercase Greek Alpha may have identical glyphs, but they are different characters. At the same time, the glyphs for uppercase Latin A can look very different in Times New Roman, Gill Sans and Poetica chancery italic, but they still represent the same character. The set of available characters is called a character repertoire . The location (index) of a given character within a repertoire is known as its code position, or code point. The method of numerically representing a code point within a given repertoire is called the character encoding . Encodings are normally expressed in terms of octets. An octet is a group of eight binary digits, i. e. eight ones and zeros. An octet can express a numeric range between 0 and 255, or between 0x00 and 0xFF, to use hexadecimal notation. A Unicode is a character repertoire that contains most of the characters used in the languages of the world. It can accommodate millions of characters, and already contains hundreds of thousands. Unicode is divided into planes of 64K characters. The only one used in most circumstances is the first plane, known as the basic multilingual plane, or BMP. UTF-8 is the recommended encoding. It uses a variable number of octets to represent different characters. In a JRXML file, the encoding attribute is specified in the header. It is used at report compilation time to decode the XML content. For instance, if the report contains French words only and characters such as ccedil, eacute, acirc, then the ISO-8859-1 (a. k.a Latin-1) encoding is sufficient minus As seen above, ideally we can choose the encoding fit to the minimal character set, which can correctly represent all the characters in the document. But in case of Multilanguage documents (i. e. documents containing words spelled in several languages), one should choose the encoding adapted to the minimal character set, able to correctly represent all the characters in the document, even if they belong to different languages. One of the character encodings able to handle multilingual documents is the UTF-8 . used as default encoding value by JasperReports. The texts are usually kept in resource bundle files rather than within the document during internationalization. So, there are cases where the JRXML itself looks completely ASCII-compatible, but generated reports at runtime do contain texts unreadable with ASCII. As a result, for a certain type of document export formats (such as CSV, HTML, XHTML, XML, and text) one has to know the encoding for the generated document too. Different languages are supported by different character encodings. So each time, we need to run a report in a localized environment. Further, we have to know, which is the most appropriate character encoding for the generated document language. In this case, the encoding property defined in the JRXML file itself might be no more useful. To solve this kind of issues we can use an export customer property known as net. sf. jasperreports. export. character. encoding . This export custom property is default to UTF-8 and is present in JasperReports. This default value is set in the default. jasperreports. properties file. For more specific options at export time, the CHARACTERENCODING export parameter is also available. To demonstrate using unicode support in Jasperreports, lets write new report template (jasperreporttemplate. jrxml). Save it to C:toolsjasperreports-5.0.1test directory. Here, we will display a text in different languages using the Unicode characters (uXXXX). Any character encoded with UTF-8 can be represented using only its 4-digits hexadecimal code. For instance, the Greek letter can be written as u0393. When such a notation is encountered, the engine calls for the appropriate character representation in the character set, and only that particular character will be printed out. The contents of the JRXML are as below minus In the above file, we can see the presence of the UTF-8 encoding. Also the localized Unicode pieces of text are stored in document parameters. The java code to fill and generate the report is as below. Lets save this file JasperUnicodeReportFill. java to C:toolsjasperreports-5.0.1testsrccomtutorialspoint directory. Here we use an instance of JREmptyDataSource when filling reports to simulate a data source with one record in it, but with all the fields in this single record being null . Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as below. The import file - baseBuild. xml is picked from chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperUnicodeReportFill (viewFullReport is the default target) as follows minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the text being displayed is in different languages. Also we see that the languages are grouped together on the same page and also mixed into the same text element. Report Styles JasperReports has a feature ltstylegt which helps to control text properties in a report template. This element is a collection of style settings declared at the report level. Properties like foreground color, background color, whether the font is bold, italic, or normal, the font size, a border for the font, and many other attributes are controlled by ltstylegt element. Styles can extend other styles, and add to, or override properties of the parent style as well. Style Properties A ltstylegt element has many attributes. Some of the most commonly used are listed in the table given below minus Attribute and Description Conditional Styles In some situations, a style should be applied only when certain condition is met (for example, to alternate adjacent row colors in a report detail section). This can be achieved using conditional styles. A conditional style has two elements minus a Boolean condition expression a style The style is used only if the condition evaluates to true . Applying Styles to Report Elements Any type of report element can reference a report style definition using the style attribute. Hence, all the style properties declared by the style definition that are applicable to the current element will be inherited. To override the inherited values, style properties specified at the report element level can be used. Style Templates We can make a set of reports with a common look by defining the style at a common place. This common style template can then be referenced by the report templates. A style template is an XML file that contains one or more style definitions. Style template files used by convention the. jrtx extension, but this is not mandatory. A style template contains following elements minus ltjasperTemplategt minus This is the root element of a style template file. lttemplategt minus This element is used to include references to other template files. The contents of this element are interpreted as the location of the referred template file. ltstylegt minus This element is identical to the element with the same name from report design templates (JRXML files), with the exception that a style in a style template cannot contain conditional styles. This limitation is caused by the fact that conditional styles involve report expressions, and expressions can only be interpreted in the context of a single report definition. References to style templates are included in JRXML reports as lttemplategt elements. The style templates are loaded at report fill time, and style name references are resolved once all the templates have been loaded. When loading style templates and resolving style names to styles, a treegraph of style templates is created, the top of the tree being the set of styles defined in the report. On this tree, style name references are resolved to the last style that matches the name in a depth-first traversal. Lets try out the conditional styles and style templates. Lets add the lt style gt element alternateStyle to our existing report template (Chapter Report Designs ). Based on the condition, font color changes to blue for even count. We have also included a style template styles. jrtx . The revised report template (jasperreporttemplate. jrxml) is as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The contents of style template styles. jrtx are as follows. Save it to C:toolsjasperreports-5.0.1test directory. The java codes for report filling remain unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the color of the font is changed to blue for even count (in column country). In the column name, the font color is changed to green (this style is referenced from the style template). Report Scriptlets We have seen in our previous chapters, data displayed on the report is usually fetched from report parameters and report fields. This data can be processed using the report variables and their expressions. There are situations when a complex functionality cannot be achieved easily using report expressions or variables. Examples of this may be complex String manipulations, building of Maps, or Lists of objects in memory or manipulations of dates using 3rd party Java APIs. For such situations, JasperReports provides us with a simple and powerful means of doing this with Scriptlets . Scriptlets are sequences of Java code that are executed every time a report event occurs. Values of report variables can be affected through scriptlets. Scriptlet Declaration We can declare a scriptlet in two ways minus Using lt scriptlet gt element. This element has name attribute and class attribute. The class attribute should specify the name of the class, which extends JRAbstractScriptlet class. The class must be available in the classpath at report filling time and must have an empty constructor, so that the engine can instantiate it on the fly. Using the attribute scriptletClass of the element lt jasperReport gt, in the report template (JRXML). By setting this attribute with fully qualified name of scriptlet (including the entire package name), we indicate that we want to use a scriptlet. The scriptlet instance, created with this attribute, acts like the first scriptlet in the list of scriptlets and has the predefined name REPORT. Scriptlet class A scriptlet is a java class, which must extend either of the following classes minus net. sf. jasperreports. engine. JRAbstractScriptlet minus This class contains a number of abstract methods that must be overridden in every implementation. These methods are called automatically by JasperReports at the appropriate moment. Developer must implement all the abstract methods. net. sf. jasperreports. engine. JRDefaultScriptlet minus This class contains default empty implementations of every method in JRAbstractScriptlet. A developer is only required to implement those methods heshe needs for hisher project. The following table lists the methods in the above class. These methods will be called by the report engine at the appropriate time, during report filling phase. Method and Description public void afterDetailEval() Called after each record in the detail section of the report is evaluated. Any number of scriptlets can be specified per report. If no scriptlet is specified for a report, the engine still creates a single JRDefaultScriptlet instance and registers it with the built-in REPORTSCRIPTLET parameter. We can add any additional methods that we need to our scriptlets. Reports can call these methods by using the built-in parameter REPORTSCRIPTLET. Global Scriptlets We can associate scriptlets in another way to reports, which is by declaring the scriptlets globally. This makes the scriptlets apply to all reports being filled in the given JasperReports deployment. This is made easy by the fact that scriptlets can be added to JasperReports as extensions. The scriptlet extension point is represented by the net. sf. jasperreports. engine. scriptlets. ScriptletFactory interface. JasperReports will load all scriptlet factories available through extensions at runtime. Then, it will ask each one of them for the list of scriptlets instances that they want to apply to the current report that is being run. When asking for the list of scriptlet instances, the engine gives some context information that the factory could use in order to decide, which scriptlets actually apply to the current report. Report Governors Governors are just an extension of global scriptlets that enable us to tackle a problem of report engine entering infinite loop at runtime, while generating reports. Invalid report templates cannot be detected at design time, because most of the time, the conditions for entering the infinite loops depend on the actual data that is fed into the engine at runtime. Report Governors help in deciding whether a certain report has entered an infinite loop and they can stop it. This prevents resource exhaustion for the machine that runs the report. JasperReports has two simple report governors that would stop a report execution based on a specified maximum number of pages or a specified timeout interval. They are minus net. sf. jasperreports. governors. MaxPagesGovernor minus This is a global scriptlet that is looking for two configuration properties to decide if it applies or not to the report currently being run. The configuration properties are minus net. sf. jasperreports. governors. TimeoutGovernor minus This is also a global scriptlet that is looking for the following two configuration properties to decide if it applies or not. The configuration properties are minus The properties for both governors can be set globally, in the jasperreports. properties file, or at report level, as custom report properties. This is useful because different reports can have different estimated size or timeout limits and also because you might want turn on the governors for all reports, while turning it off for some, or vice-versa. Lets write a scriptlet class ( MyScriptlet ). The contents of file C:toolsjasperreports-5.0.1testsrccomtutorialspointMyScriptlet. java are as follows minus Details of the above scriptlet class are as follows minus In the afterReportInit method, we set a value to the variable someVar this. setVariableValue(someVar, new String(This variable value was modified by the scriptlet.)). At the end of the class, an extra method called hello has been defined. This is an example of a method that can be added to the Scriptlet that actually returns a value, rather than setting a Variable. Next, we will add the scriptlet class reference in our existing report template (Chapter Report Designs ). The revised report template (jasperreporttemplate. jrxml) are as follows. Save it to C:toolsjasperreports-5.0.1test directory minus The details of the revised report template is given below minus We have referenced the MyScriptlet class in the attribute scriptletClass of ltjasperReportgt element. Scriptlets can only access, but not modify the report fields and parameters. However, scriptlets can modify report variable values. This can be accomplished by calling the setVariableValue() method. This method is defined in JRAbstractScriptlet class, which is always the parent class of any scriptlet. Here, we have defined a variable someVar . which will be modified by the MyScriptlet to have the value This value was modified by the scriptlet . The above report template has a method call in the Summary band that illustrates how to write new methods (in scriptlets) and use them in the report template. ( P. hello() ) The java codes for report filling remain unchanged. The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java are as given below minus The contents of the POJO file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java are as given below minus The contents of the file C:toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java are as given below minus Report Generation We will compile and execute the above file using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport is the default target) as minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here we see two messages are displayed from MyScriptlet class minus In title section minus This variable value was modified by the scriptlet At the bottom minus Hello Im the reports scriptlet object. Create SubReports Subreports are one of the nice features of the JasperReports. This feature allows incorporating a report within another report, that is, one report can be a subreport of another. Subreports help us keep report designs simple, as we can create many simple reports and encapsulate them into a master report. Subreports are compiled and filled just like normal reports. Any report template can be used as a subreport when incorporated into another report template, without anything changed inside (of the report template). Subreports are like normal report templates. They are in fact net. sf. jasperreports. engine. JasperReport objects, which are obtained after compiling a net. sf. jasperreports. engine. design. JasperDesign object . ltsubreportgt Element A ltsubreportgt element is used when introducing subreports into master reports. Here is the list of sub-elements in the ltsubreportgt JRXML element. ltparametersMapExpressiongt minus This is used to pass a map containing report parameters to the subreport. The map is usually obtained from a parameter in the master report, or by using the built-in REPORTSPARAMETERSMAP parameter to pass the parent reports parameters to the subreport. This expression should always return a java. util. Map object in which the keys are the parameter names. ltsubreportParametergt minus This element is used to pass parameters to the subreport. It has an attribute name . which is mandatory. ltconnectionExpression gt minus This is used to pass a java. sql. Connection to the subreport. It is used only when the subreport template needs a database connection during report filling phase. ltdataSourceExpressiongt minus This is used to pass a datasource to the subreport. This datasource is usually obtained from a parameter in the master report or by using the built-in REPORTDATASOURCE parameter to pass the parent reports datasource to the subreport. The elements ( connectionExpression and dataSourceExpression ) cannot be present at the same time in a ltsubreportgt element declaration. This is because we cannot supply both a data source and a connection to the subreport. We must decide on one of them and stick to it. ltreturnValuegt minus This is used to assign the value of one of the subreports variables to one of the master reports variables. This sub element has attributes as follows minus subreportVariable minus This attribute specifies the name of the subreport variable whose value is to be returned. toVariable minus This attribute specifies the name of the parent report variable whose value is to be copiedincremented with the value from the subreport. calculation minus This attribute can take values. Nothing, Count, DistinctCount, Sum, Average, Lowest, Highest, StandardDeviation, Variance. Default value for attribute calculation is Nothing. incrementerFactoryClass minus This attribute specifies the factory class for creating the incrementer instance. ltsubreportExpressiongt minus This indicates where to find the compiled report template for the subreport. This element has a class attribute. The class attribute can take any of these values:java. lang. String, java. io. File, java. URL, java. io. InputStream, net. sf. jasperreports. engine. JasperReport. Default value is java. lang. String . isUsingCache minus This is an attribute of the ltsubreportgt element. This is a Boolean, when set to true . the reporting engine will try to recognize previously loaded subreport template objects, using their specified source. This caching functionality is available only for subreport elements that have expressions returning java. lang. String objects as the subreport template source, representing file names, URLs, or classpath resources. Let take up a simple example to demonstrate creation of subreports using JRDataSource. Lets first write two new report templates, one being subreport and the other Master report. The contents of the subreport (addressreporttemplate. jrxml) template is as given below. Save it to C:toolsjasperreports-5.0.1test directory. As we use a data source, we need to write a corresponding POJO file SubReportBean. java as shown below. Save it to directory C:toolsjasperreports-5.0.1testsrccomtutorialspoint minus Here, we have declared two fields city and street and respective getter and setter methods are defined. Now, lets update our existing DataBean file. We will add a new field subReportBeanList . which is a java. util. List. This field will hold the list of SubReportBean objects. The contents of the file DataBean are as below. Save it to directory C:toolsjasperreports-5.0.1testsrccomtutorialspoint. Lets now update the file C:toolsjasperreports-5.0.1testsrccomtutorialspoint DataBeanList. java . The contents of this file are as minus In the method produce() in the above file, we are setting the list of SubReportBean. Now, lets write a new master report template (jasperreporttemplate. jrxml). Save this file to directory C:toolsjasperreports-5.0.1test . The contents for this file are as below minus In the above template, we have defined a new parameter SUBREPORTDIR, which defines the path of the subreport. We have defined a field subReportBeanList of type java. util. List, which corresponds to property in the file DataBean. The element ltsubreportgt has sub-element ltdataSourceExpressiongt. We have put the list subReportBeanList in an instance of JRBeanCollectionDataSource. In the sub-element ltsubreportExpressiongt, we have given the subreport name (AddressReport. jasper). Now, lets write a new class CreateReport to compile and execute our report template. The contents of file C:toolsjasperreports-5.0.1testsrccomtutorialspointCreateReport. java are as given below minus Here, we see that we are compiling both the master and sub report templates and passing the master report (.jasper) file for the report filling. Report Generation Now, all our files are ready, lets compile and execute them using our regular ANT build process. The contents of the file build. xml (saved under directory C:toolsjasperreports-5.0.1test) are as given below. The import file - baseBuild. xml is picked up from the chapter Environment Setup and should be placed in the same directory as the build. xml. Next, lets open command line window and go to the directory where build. xml is placed. Finally, execute the command ant - Dmain-classcom. tutorialspoint. CreateReport (viewFullReport is the default target) as follows minus As a result of above compilation, a JasperViewer window opens up as shown in the screen given below minus Here, we can see that the attributes Name, Country, and Address are displayed. Creating Charts Earlier people had to rely on scriptlets to gather the chart data and render the chart using an image element in the report template. JasperReports makes it simple now, as it has a built-in support for charts using the new chart component. Using a new chart component, user needs to apply only the visual settings and define expressions that will help build the chart dataset. JasperReports uses JFreeChart as the underlying charting library. When configuring a new chart component, following three components are involved minus The overall chart component. The chart dataset (which groups chart data-related settings). The chart plot (which groups visual settings related to the way the chart items are rendered). JasperReports currently supports the following types of charts: Pie, Pie 3D, Bar, Bar 3D, XY Bar, Stacked Bar, Stacked Bar 3D, Line, XY Line, Area, XY Area, Stacked Area, Scatter, Bubble, Time Series, High-Low-Open-Close, Candlestick, Multiple Axis, Meter, Thermometer, and Gantt. Chart Properties Charts are normal report elements, so they share some of their properties with all the other report elements. There is a JRXML element called lt chart gt, used to create all type of charts. This element groups special chart-specific settings that apply to all types of charts. Chart Sub-Elements The sub-elements of ltchartgt element are minus ltreportElementgt minus These are displayable objects like static texts, text fields, images, lines, and rectangles that you put in your report template sections. ltBoxgt minus This element is used to surround charts by a border thats customizable on each side. ltchartTitlegt minus This element is used to place the title of the chart. The position attribute decides the title position of the chart in the report. This element has attributes - Position (Values could be Top . Bottom . Left . Right . Deafult value is Top ), color . ltchartTitlegt has font and titleExpression as subelements. ltchartSubtitlegt minus This element is used to place the subtitle of the chart. This element has attribute - color . ltchartSubtitlegt has font and subtitleExpression as subelements. ltchartLegendgt minus The element can control the font-related properties as well as the text color and the background color of the chart legend using this element. This element has attributes - textColor and backgroundColor . ltanchorNameExpressiongt minus This element creates the target for the anchor. lthyperlinkReferenceExpressiongt minus This element contains a report expression indicating the name of the external resource (usually a URL). lthyperlinkAnchorExpressiongt minus Hyperlink points to an anchor in an external resource. lthyperlinkPageExpressiongt minus Hyperlink points to a page in the current report. lthyperlinkTooltipExpressiongt minus This element controls the ToolTip of hyperlink. The type of the expression should be java. lang. String . lthyperlinkParametergt minus This element when present generates a final hyperlink depending on the parameter values. Chart attributes Attributes in the ltchartgt element available for all chart types are minus isShowLegend minus This attribute is used to determine, if a chart legend will be displayed on the report. Values could be true . or false . Default value is true . evaluationTime minus Determines when the charts expression will be evaluated. Values could be Now . Report . Page . Column . Group . Band . Default value is Now . evaluationGroup minus This attribute determines the name of the group to be used to evaluate the charts expressions. The value for this attribute must match the name of the group, we would like to use as the charts evaluation group. hyperlinkType minus This attribute can hold any text value. Default value is None . This means, neither the text fields nor the images represent hyperlinks, even if the special hyperlink expressions are present. hyperlinkTarget minus This attribute helps to customize the behavior of the specified link when it is clicked in the viewer. Values could be Self . or Blank . Default value is Self . bookmarkLevel minus This attribute when set to a positive integer, generates bookmarks in the reports exported to PDF. Default value is 0 . customizerClass minus This is the name of a class (optional) that can be used to customize the chart. The value for this element must be a String containing the name of a customizer class. Chart customization As mentioned above, JasperReports uses JFreeChart as the underlying charting library. JFreeChart contains features that are directly not supported by JasperReports. We can take advantage of these features by supplying a customizer class via the customizerClass attribute in ltchartgt element. A customizer class is nothing, but an implementation of the net. sf. jasperreports. engine. JRChartCustomizer interface. The easiest way to implement this interface is by extending the net. sf. jasperreports. engine. JRAbstractChartCustomizer class and thus having access to parameters, fields, and variables for more flexible chart customization based on report data. Chart Datasets One of the common properties across all chart types is lt dataset gt element. Chart datasets help mapping report data and retrieving chart data at runtime. Each chart type contains different sub-elements to define charts expressions. These expressions define the data used to generate the chart. All of these sub-elements contain a ltdatasetgt element that defines when the charts expressions are evaluated and reset. Several types of chart datasets are available in JasperReports because each type of chart works with certain datasets: Pie, Category, XY, Time Series, Time Period, XYZ, and High-Low. Each of these dataset types implements net. sf. jasperreports. engine. JRChartDataset interface that define chart datasets. All chart datasets initialize and increment in the same way however, they differ only in the type of data or data series they map. Dataset Properties Table given below summarizes the attributes of the element ltdatasetgt minus JasperReports - Crosstabs JasperReports - Internationalization

No comments:

Post a Comment