Tuesday 4 July 2017

Moving Average Jfreechart


2009-08-06: pelepasan 0.6.0 dirilis 2009-05-22: pelepasan 0.5.0 dilepaskan 2009-03-16: pelepasan 0.5.0 beta. 2008-06-20: rilis 0.4.1, peluncuran kembali situs Wiki dan penyertaan forum sebagai halaman tersemat: Forum Pengguna dan Forum Pengembang. Nikmati 2008-05-04 Appendium Ltd dan LavaBlast dengan bangga mengumumkan perilisan versi 0.4.0 dari StatSVN. Detail lebih lanjut tentang blog ini dan changelog. 2007-03-10 Berita Sebagai bagian dari rilis 0.3.1, kami telah meluncurkan serangkaian demo untuk beberapa proyek yang telah dikenal: Subversion, Ant, Log4J, Klien Kaya Musim Semi, Hibernate 3, Joda Time, Ruby, Groovy, Grails dan Felix untuk memulai. Ayo, akui, kamu selalu ingin tahu siapa yang melakukan apa dan kapan proyek itu. PERINGATAN . Jika Anda tidak menggunakan bahasa Inggris, tolong atur variabel lingkungan LANG ke enUS saat menjalankan aplikasi sampai kami menyelesaikan beberapa masalah i18n dengan StatSVN (panggilan ke svn diff mengembalikan string lokal yang dapat mengakibatkan beberapa hasil tidak di-cache, hasilnya Benar tapi StatSVN akan meminta mereka lagi lain kali). 2007-02-07: Ingin membantu mempertimbangkan untuk mengganti perintah perintah kami dengan panggilan ke SVNKit (dahulu JavaSVN). Ingin menulis implementasi prototipe dan melihat seberapa baik kinerjanya Mari kita ketahui 2007-01-12: Versi 0.3.0 ada di SVN dan menambahkan 2 laporan (RepoMap dan LOCChurn) serta memperbaiki sejumlah masalah dengan file bergerak, direktori Dan penghapusannya. Detail lebih lanjut di halaman ini. 2006-11-28: Versi 0.2.0 sudah keluar dan sekarang mendukung generasi Html dan XDoc untuk memudahkan integrasi dengan Maven (lihat laporan di sini). Yang juga senang menyebutkan bahwa ada plugin Maven 2 yang menggunakan StatSVN, tersedia di stat-scm. sourceforge. Menciak Menciak dari Penulis Jadi, statistik StatSVN yang Great untuk SVN StatSVN mengambil informasi dari repositori Subversion dan menghasilkan berbagai tabel dan grafik yang menjelaskan pengembangan proyek, mis. Garis waktu untuk baris kode Baris kode untuk setiap pengembang Aktivitas menurut Jam Penulis Kegiatan Pengarang Aktivitas per Modul Pengarang Paling Baru Berkomitmen dengan tautan ke Statistik ViewVc per direktori Jumlah file Ukuran file rata-rata File terbesar Berkas dengan revisi terbanyak Ukuran Direktori Tag Repositori Jumlah LOC per versi Pohon repositori dengan jumlah file dan baris kode LOC dan menggerakkan evolusi LOC dan jumlah perubahan per hari Repo Peta tampilan hirarkis dinamis repo Anda selama 30 hari terakhir Versi StatSVN saat ini menghasilkan rangkaian dokumen HTML statis yang berisi Tabel dan bagan gambar. StatSVN adalah perangkat lunak open source, dirilis berdasarkan persyaratan LGPL, berdasarkan StatCVS. StatSVN menggunakan JFreeChart untuk menghasilkan grafik. Di sini manualnya tersedia secara online sebagai Wiki dan ini serba mutakhir dan komprehensif sesuai keinginan Anda. Contoh Cepat untuk Maven 1 Sebelum menjalankan situs maven (atau hanya maven xdoc), Anda dapat menghasilkan file XDOC dengan menjalankan: (jangan lupa - v). Contoh ini akan menghasilkan xdoc di direktori sitestatsvn, tag 0.2.0, 0.1.3, 0.1.2, 0.0.9, tidak termasuk qalab. xml dan lain-lain. Setelah itu XDOC akan dijemput oleh situs maven atau maven xdoc. Perlu diketahui bahwa untuk menggunakan tag, Anda harus menggunakan file log tidak di tingkat bagasi tapi tepat di atas, untuk memasukkan direktori tag. Saat ini, StatSVN hanya bekerja dengan direktori tag. Contoh Cepat dari dump baru Ada fasilitas dump baru (jangan lupa - v). Ini akan menghasilkan sejumlah besar output namun pada akhirnya, jika ini menunjukkan OK untuk semua kemungkinan StatSVN memahami repositori Anda dengan benar: JasperReports - Panduan Cepat JasperReports - Memulai JasperReports - Setup Lingkungan JasperReports - Life Cycle JasperReports - Desain JasperReports - Mengumpulkan Laporan Desain JasperReports - Mengisi Laporan Laporan Jasper - Lihat amp Laporan Cetak JasperReports - Mengekspor Parameter Laporan Laporan Jika disetel ke java. lang. Boolean. TRUE, laporan akan dibuat dalam satu halaman panjang dan jeda halaman tidak akan terjadi. Mari kita sampaikan ReportTitle dan Author ke laporan (dihasilkan oleh JasperReportFill. java). Berkas yang direvisi C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java adalah sebagai berikut minus Isi file POJO C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java adalah sebagai berikut minus Isi dari file C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java adalah sebagai Diberikan di bawah minus Mari kita tambahkan parameter lt ReportTitle gt dan lt Penulis ke template laporan yang ada (Bab Laporan Desain). Judul Laporan dan Penulis akan ditampilkan di awal laporan. Template revisi laporan (jasperreporttemplate. jrxml) adalah sebagai berikut. Simpan ke C: toolsjasperreports-5.0.1test directory minus Report Generation Kami akan mengkompilasi dan mengeksekusi file di atas menggunakan proses build ANT reguler kami. Isi dari file build. xml (disimpan di bawah direktori C: toolsjasperreports-5.0.1test) adalah seperti di bawah ini. File impor - baseBuild. xml dipilih dari bab Environment Setup dan harus ditempatkan di direktori yang sama dengan build. xml. Selanjutnya, mari kita buka jendela command line dan masuk ke directory tempat build. xml diletakkan. Akhirnya, jalankan perintah ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport adalah target default) sebagai berikut minus Sebagai hasil kompilasi di atas, jendela JasperViewer terbuka seperti ditunjukkan pada layar berikut minus Di sini, kita melihat bahwa, ReportTitle Daftar Kontak dan Penulis Disusun Oleh Manisha ditampilkan di awal laporan. Sumber Data Laporan Sumber data adalah data terstruktur. Saat membuat laporan, mesin JasperReports memperoleh data dari datasources. Data bisa didapat dari database, file XML, array objek, dan koleksi objek. Kami melihat dalam Bab Mengisi Laporan. Metode fillReportXXX () mengharapkan untuk menerima sumber data laporan, yang harus diisi, dalam bentuk objek net. sf. jasperreports. engine. JRDataSource atau java. sql. Connection (saat data laporan ditemukan di sebuah Database relasional). Antarmuka JRDataSource hanya memiliki dua metode, yang harus diterapkan dikurangi boolean publik berikutnya () melempar JRException Pada waktu mengisi laporan, metode ini disebut pada objek sumber data oleh mesin pelaporan saat melakukan iterasi melalui data. Objek publik getFieldValue (JRField jrField) melempar JRException Metode ini memberikan nilai untuk setiap bidang laporan dalam catatan sumber data saat ini. Satu-satunya cara untuk mengambil data dari sumber data adalah dengan menggunakan kolom laporan. Ada beberapa implementasi default dari antarmuka JRDataSource, tergantung pada jalannya, catatan sumber data diperoleh. Implementasi Datasource Tabel yang diberikan di bawah merangkum datasources dan kelas pelaksanaannya dikurangi Sumber Data JDBC Class JRResultSetDataSource craps sebuah objek java. sql. ResultSet. Ini adalah implementasi sumber data yang paling umum digunakan saat data laporan diekstraksi dari database relasional. Jika java. sql. Connection dilewatkan ke mesin sebagai gantinya, ia menjalankan query yang pertama dan menyimpan objek java. sql. ResultSet yang dikembalikan dalam instance JRResultSetDataSource. Sumber Data JavaBean Classes JRBeanArrayDataSource dan JRBeanCollectionDataSource merupakan implementasi yang dapat membungkus array dan koleksi objek JavaBean. Setiap objek di dalam array atau koleksi akan dilihat sebagai satu record dalam jenis sumber data ini. Pemetaan antara properti JavaBean tertentu dan kolom laporan yang sesuai dibuat dengan menamai konvensi. Nama field laporan harus sama dengan nama properti JavaBean seperti yang ditentukan oleh spesifikasi JavaBeans. Dalam semua contoh tutorial ini, kami telah menggunakan JRBeanCollectionDataSource. Sumber Data Berbasis Peta Kelas implementasi JRMapArrayDataSource dan JRMapCollectionDataSource berguna jika aplikasi induk sudah menyimpan data pelaporan yang ada di memori sebagai objek java. util. Map. Setiap objek Map dalam array atau koleksi yang dibungkus dianggap sebagai catatan virtual dalam sumber data, dan nilai setiap bidang laporan diambil dari peta menggunakan bidang laporan yang dinamai sebagai kuncinya. Sumber Data TableModel Di banyak aplikasi sisi klien, data ditampilkan dalam format tabel. Persyaratan umum dalam banyak aplikasi adalah mengizinkan pengguna untuk mencetak format tabular ini sebagai laporan. Kelas implementasi JRTableModelDataSource membuat tugas menghasilkan laporan dari format tabel yang sepele untuk aplikasi Swing. Kelas ini membungkus objek javax. swing. table. TableModel. Kolom dalam objek TableModel yang dibungkus dapat diakses dengan nama mereka atau berdasarkan indeks berbasis 0 mereka. Sumber Data XML Class JRXmlDataSource adalah implementasi sumber data berbasis DOM, yang menggunakan ekspresi XPath untuk memilih data dari dokumen XML. Catatan dalam sumber data XML diwakili oleh elemen simpul yang dipilih melalui ekspresi XPath. Nilai field diambil dari masing-masing record menggunakan ekspresi XPath yang diberikan oleh field description (elemen ltfieldDescriptiongt di JRXML). XPath adalah bahasa yang digunakan untuk menavigasi atribut dan elemen dokumen XML. Informasi lebih lanjut tentang XPath dapat ditemukan di w3.orgTRxpath. Sumber Data CSV JRCsvDataSource mewakili implementasi untuk sumber data, yang mengambil data mereka dari file teks terstruktur yang biasanya CSV. Nilai field diambil menggunakan indeks kolom mereka. Sumber Data XLS JRXlsDataSource mewakili sebuah implementasi untuk sumber data, yang mengambil datanya dari dokumen Excel. Pemetaan lapangan laporan untuk implementasi sumber data ini juga didasarkan pada indeks kolom lapangan. Sumber Data Kosong Kelas JREmptyDataSource. Mensimulasikan sumber data dengan sejumlah catatan virtual kosong di dalamnya. Ini digunakan oleh alat UI untuk menawarkan fungsionalitas pratinjau laporan dasar, atau dalam template laporan khusus, atau untuk tujuan pengujian dan debugging. Sumber Data Rewindable The net. sf. jasperreports. engine. JRRewindableDataSource memperluas antarmuka JRDataSource dasar. Ini hanya menambahkan satu metode, yang disebut moveFirst (), ke antarmuka. Metode ini dimaksudkan untuk memindahkan kursor ke elemen pertama dalam sumber data. Sumber data yang dapat diedit berguna saat bekerja dengan sub-laporan yang ditempatkan di dalam band yang tidak diizinkan untuk dipecah karena pengaturan isSplitAllowedfalse dan tidak ada cukup ruang pada halaman ini untuk sub laporan yang akan diberikan. Semua implementasi sumber data di atas dapat ditulis ulang kecuali untuk JRResultSetDataSource. Karena tidak mendukung penggerak record record kembali. Ini menimbulkan masalah hanya jika sumber data ini digunakan secara manual untuk membungkus java. sql. ResultSet sebelum mengirimkannya ke sub-laporan. Tidak ada masalah, jika query SQL berada di template sub-laporan, karena mesin akan menjalankannya lagi saat me-restart sub-laporan di halaman berikutnya. Penyedia Sumber Data Perpustakaan JasperReports memiliki antarmuka net. sf. jasperreports. engine. JRDataSourceProvider. Ini membantu dalam menciptakan dan membuang sumber data objek. Saat membuat template laporan menggunakan alat GUI, alat khusus untuk menyesuaikan sumber data laporan diperlukan. JRDataSourceProvider adalah cara standar untuk menyambungkan sumber data khusus ke dalam peranti desain. Implementasi kustom dari antarmuka ini harus menerapkan metode berikut yang memungkinkan pembuatan dan pembuangan objek sumber data dan juga metode untuk mencantumkan bidang laporan yang tersedia di dalam sumber data jika mungkin dikurangi bidang Laporan Bidang Laporan adalah elemen, yang mewakili pemetaan data antara sumber data Dan template laporan Bidang dapat dikombinasikan dalam ekspresi laporan untuk mendapatkan output yang diinginkan. Template laporan dapat berisi elemen ltfieldgt nol atau lebih. Saat mendeklarasikan bidang laporan, sumber data harus menyediakan data yang sesuai dengan semua bidang yang didefinisikan dalam template laporan. Deklarasi Lapangan Deklarasi lapangan dilakukan seperti yang ditunjukkan di bawah ini minus Atribut Nama Atribut nama elemen ltfieldgt adalah wajib. Ini merujuk ke lapangan dalam ekspresi laporan berdasarkan nama. Atribut Kelas Atribut kelas menentukan nama kelas untuk nilai field. Nilai awalnya adalah java. lang. String. Hal ini dapat diubah ke kelas yang tersedia saat runtime. Terlepas dari jenis bidang laporan, mesin menangani pengecoran dalam ungkapan laporan dimana token F digunakan, sehingga membuat cetakan manual tidak perlu. Deskripsi Lapangan Elemen ltfieldDesciptiongt adalah elemen opsional. Ini sangat berguna saat mengimplementasikan sumber data khusus. Misalnya, kita dapat menyimpan kunci atau beberapa informasi, dengan mana kita dapat mengambil nilai bidang dari sumber data khusus saat runtime. Dengan menggunakan elemen ltfieldDesciptiongt alih-alih nama field, Anda dapat dengan mudah mengatasi pembatasan konvensi penamaan lapangan saat mengambil nilai field dari sumber data. Berikut adalah potongan kode dari file JRXML yang ada (Chapter Report Designs). Disini kita bisa melihat penggunaan nama. Kelas. Dan elemen fieldDescription. Sort Fields Pada saat penyortiran data diperlukan dan implementasi sumber data tidak mendukungnya (misalnya, sumber data CSV), JasperReports mendukung penyortiran sumber data berbasis memori di memori. Pemilahan dapat dilakukan dengan menggunakan satu atau lebih elemen ltsortFieldgt dalam template laporan. Jika setidaknya satu bidang sortir ditentukan, selama proses pengisian laporan, sumber data dilewatkan ke instance JRSortableDataSource. Hal ini pada gilirannya, mengambil semua data dari sumber data, melakukan dalam bentuk memori sesuai dengan bidang yang ditentukan, dan menggantikan sumber data asli. Nama field sort harus sama dengan nama kolom laporan. Bidang yang digunakan untuk sortasi harus memiliki tipe yang mengimplementasikan java. utilparable. Penyortiran urutan natural dilakukan untuk semua bidang kecuali tipe java. lang. String (untuk tipe String, collator yang sesuai dengan lokal isi laporan digunakan). Ketika beberapa jenis Fields ditentukan, sortasi akan dilakukan dengan menggunakan kolom sebagai kunci sortir sesuai urutan tampilan di template laporan. Contoh berikut menunjukkan fitur pemilahan. Contoh Laporan Diurutkan Mari menambahkan elemen lt sortField gt ke template laporan kami yang ada (Bab Laporan disain). Memungkinkan mengurutkan bidang negara dalam urutan menurun. Template revisi laporan (jasperreporttemplate. jrxml) adalah sebagai berikut. Simpan ke C: toolsjasperreports-5.0.1test direktori dikurangi Kode java untuk pengisian laporan tetap tidak berubah. Isi dari file C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java adalah seperti yang diberikan di bawah ini minus Isi dari file POJO C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java adalah seperti yang diberikan di bawah minus Isi dari file C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java adalah seperti yang diberikan di bawah minus Laporan generasi Kami akan mengkompilasi dan mengeksekusi file di atas dengan menggunakan proses build ANT reguler kami. Isi dari file build. xml (disimpan di bawah direktori C: toolsjasperreports-5.0.1test) adalah seperti yang diberikan di bawah ini. File impor - baseBuild. xml dipilih dari bab Environment Setup dan harus ditempatkan di direktori yang sama dengan build. xml. Selanjutnya, mari kita buka jendela command line dan masuk ke directory tempat build. xml diletakkan. Akhirnya, jalankan perintah ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport adalah target default) sebagai berikut minus Sebagai hasil dari kompilasi di atas, jendela JasperViewer terbuka seperti yang ditunjukkan pada layar yang diberikan di bawah minus Di sini, kita dapat melihat bahwa Nama negara disusun dalam urutan menurun menurut abjad. Ungkapan Laporan Ekspresi Laporan adalah fitur hebat JasperReports, yang memungkinkan kami menampilkan data yang dihitung pada laporan. Data yang dihitung adalah data yang bukan data statis dan tidak secara khusus dilewatkan sebagai parameter laporan atau field data sumber. Ekspresi laporan dibuat dari gabungan parameter laporan, field, dan data statis. Bahasa Jawa digunakan untuk menulis ekspresi laporan secara default. Bahasa scripting lainnya untuk ekspresi laporan seperti skrip bahasa scripting, JavaScript, atau BeanShell didukung oleh kompiler JasperReports. Bab ini akan menjelaskan kepada Anda bagaimana ekspresi laporan bekerja, dengan asumsi bahwa tulisan tersebut hanya ditulis menggunakan bahasa Jawa saja. Dalam kerangka laporan JRXML, ada beberapa elemen yang mendefinisikan ekspresi sebagai berikut. Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi Ekspresi ekspresi Referensi Lapangan dalam Ekspresi Untuk menggunakan referensi kolom laporan dalam sebuah ekspresi, nama bidang harus diletakkan antara urutan F dan karakter, seperti yang ditunjukkan di bawah ini minus Berikut adalah potongan kode dari file JRXML yang ada (bab Desain Laporan) minus Variabel Referensi dalam Ekspresi Untuk referensi sebuah variabel dalam sebuah ekspresi, kita harus memasukkan nama variabel antara V dan seperti yang ditunjukkan pada contoh di bawah ini minus Parameter Reference in Expression Untuk mereferensi parameter dalam sebuah ekspresi, nama parameter harus diletakkan. Antara P dan seperti ditunjukkan pada contoh di bawah minus Berikut adalah potongan kode dari file JRXML yang ada, yang menunjukkan referensi parameter dalam sebuah ekspresi. (JRXML from chapter Report Designs) minus Seperti yang Anda lihat di atas, parameter, field, dan referensi variabel sebenarnya adalah objek Java nyata. Mengetahui kelas mereka dari parameter, field, atau deklarasi variabel yang dibuat dalam template laporan, kita bahkan dapat memanggil metode pada referensi objek tersebut dalam ekspresi. Contoh berikut menunjukkan minus bagaimana cara mengekstrak dan menampilkan huruf pertama dari field laporan java. lang. String Nama minus Resource Bundle Reference in Expression Untuk referensi sumber daya dalam sebuah ekspresi, kunci harus diletakkan di antara R dan seperti yang ditunjukkan pada contoh yang diberikan Di bawah minus Berdasarkan pada lokasi yang disediakan oleh runtime dan kunci report. title, bundel sumber daya yang terkait dengan template laporan dimuat. Oleh karena itu, judul laporan ditampilkan dengan mengekstraksi nilai String dari kumpulan sumber daya. Lebih lanjut tentang internasionalisasi dapat ditemukan di bab Internasionalisasi. Calculator Calculator adalah entitas dalam JasperReports, yang mengevaluasi ekspresi dan penambahan variabel atau kumpulan data pada waktu mengisi laporan. Selama proses kompilasi, informasi diproduksi dan disimpan dalam laporan kompilasi oleh kompilator. Informasi ini digunakan selama waktu mengisi laporan untuk membuat instance dari kelas net. sf. jasperreports. engine. fill. JRCalculator. File sumber Java dihasilkan dan disusun oleh kompiler laporan berbasis Java dengan cepat. Kelas yang dihasilkan ini adalah subkelas dari JRCalculator, dan bytecode yang dihasilkan oleh kompilasi disimpan di dalam objek JasperReport. Kode byt ini dimuat pada waktu pengisian laporan dan kelas yang dihasilkan diberi instantiasi untuk mendapatkan objek kalkulator yang diperlukan untuk evaluasi ekspresi. Ekspresi Bersyarat JasperReports tidak mendukung pernyataan if-else saat menentukan ekspresi variabel. Sebagai gantinya, Anda bisa menggunakan operator terner. . . Operator ini dapat bersarang di dalam ekspresi Java untuk mendapatkan output yang diinginkan berdasarkan beberapa kondisi. Contoh Ekspresi Bersyarat dalam Laporan Mari kita memodifikasi template laporan yang ada (Bab Laporan Desain) dan menambahkan ekspresi kondisional untuk negara lapangan. Template revisi laporan (jasperreporttemplate. jrxml) adalah sebagai berikut. Simpan ke C: toolsjasperreports-5.0.1test direktori dikurangi Kode java untuk pengisian laporan adalah sebagai berikut. Isi file C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java adalah sebagai minus Isi dari file POJO C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java adalah sebagai minus Kami akan menambahkan catatan baru dengan field negara kosong di kacang Java kami. Daftar. Isi file C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBeanList. java adalah sebagai minus Report Generation Kami akan mengkompilasi dan mengeksekusi file di atas menggunakan proses build ANT biasa kami. Isi dari file build. xml (disimpan di bawah direktori C: toolsjasperreports-5.0.1test) diberikan di bawah ini. File impor - baseBuild. xml dipilih dari bab Environment Setup dan harus ditempatkan di direktori yang sama dengan build. xml. Selanjutnya, mari kita buka jendela command line dan masuk ke directory tempat build. xml diletakkan. Akhirnya, jalankan perintah ant - Dmain-class com. tutorialspoint. JasperReportFill (viewFullReport adalah target default) sebagai minus Sebagai hasil dari kompilasi di atas, jendela JasperViewer terbuka seperti yang ditunjukkan pada layar yang diberikan di bawah minus Di sini, kita dapat melihat, Untuk catatan terakhir, kami belum melewati data untuk negara lapangan, NO COUNTRY sedang dicetak. Variabel Laporan Variabel laporan adalah objek khusus yang dibangun di atas ekspresi laporan. Variabel laporan menyederhanakan tugas berikut minus Ekspresi laporan, yang banyak digunakan sepanjang template laporan. Ungkapan ini dapat dinyatakan hanya sekali dengan menggunakan variabel laporan. Variabel laporan dapat melakukan berbagai perhitungan berdasarkan nilai ekspresi yang sesuai seperti hitungan, jumlah, rata-rata, terendah, tertinggi, varians, dll. Jika variabel didefinisikan dalam desain laporan, maka ini dapat direferensikan oleh variabel baru dalam ekspresi. Oleh karena itu, urutan di mana variabel dinyatakan dalam desain laporan adalah penting. Deklarasi Variabel Deklarasi variabel adalah sebagai berikut minus Seperti yang terlihat di atas, elemen ltvariablegt mengandung sejumlah atribut. Atribut ini diringkas di bawah minus Atribut Nama Mirip dengan parameter dan bidang. Atribut nama elemen ltvariablegt adalah wajib. Ini memungkinkan referensi variabel dengan nama yang dideklarasikannya dalam ungkapan laporan. Atribut Kelas Atribut kelas juga wajib yang menentukan nama kelas untuk nilai variabel. Nilai awalnya adalah java. lang. String. Hal ini dapat diubah ke kelas mana pun yang tersedia di kelas, baik pada waktu kompilasi laporan dan waktu pengisian laporan. Mesin menangani tipuan dalam ekspresi laporan yang digunakan token V, sehingga pengecekan jenis manual tidak diperlukan. Perhitungan Atribut ini menentukan minus perhitungan apa yang harus dilakukan pada variabel saat mengisi laporan. Subbagian berikut menjelaskan semua nilai yang mungkin untuk atribut perhitungan elemen ltvariablegt. Rata-rata minus Nilai variabel adalah rata-rata dari setiap nilai non-nol dari ekspresi variabel. Berlaku untuk variabel numerik saja. Count minus Nilai variabel adalah hitungan contoh non-null dari ekspresi variabel. Pertama dikurangi Nilai variabel adalah nilai instance pertama dari ekspresi variabel. Nilai selanjutnya diabaikan. Nilai minus tertinggi adalah nilai tertinggi untuk ekspresi variabel. Terendah dikurangi Nilai variabel adalah nilai terendah untuk variabel ekspresi dalam laporan. Tidak ada minus Tidak ada perhitungan yang dilakukan pada variabel. StandardDeviation minus Nilai variabel adalah standar deviasi semua nilai non-null yang sesuai dengan ekspresi laporan. Berlaku untuk variabel numerik saja. Sum minus Nilai variabel adalah jumlah semua nilai non-null yang dikembalikan oleh ekspresi laporan. Sistem minus Nilai variabel adalah perhitungan kustom (menghitung nilai untuk variabel itu sendiri, dengan menggunakan fungsi scriptlets JasperReports). Variance minus Nilai variabel adalah varians dari semua nilai non-null yang dikembalikan oleh evaluasi ekspresi variabel laporan. Incrementer FactoryClass Atribut ini menentukan kelas yang digunakan untuk menghitung nilai variabel saat mengisi catatan saat ini pada laporan. Nilai default adalah kelas yang mengimplementasikan net. sf. jasperreports. engine. fill. JRIncrementerFactory. Kelas pabrik akan digunakan oleh mesin untuk memberi instantiate objek incrementer saat runtime tergantung pada atribut perhitungan yang ditetapkan untuk variabel. IncrementType Ini menentukan kapan menghitung ulang nilai variabel. Atribut ini menggunakan nilai, seperti di bawah minus Kolom minus Nilai variabel dikalkulasi ulang pada akhir setiap kolom. Kelompok dikurangi Nilai variabel dihitung ulang bila grup ditentukan oleh perubahan GroupGambar. Tidak ada minus Nilai variabel dihitung ulang dengan setiap record. Halaman minus Nilai variabel dihitung ulang di akhir setiap halaman. Laporan minus Nilai variabel dihitung ulang satu kali, di akhir laporan. IncrementGroup Ini menentukan nama grup dimana nilai variabel dihitung ulang, ketika incrementType adalah Group. Ini mengambil nama grup yang dideklarasikan dalam template laporan JRXML. Ini menentukan kapan nilai variabel di-reset. Atribut ini menggunakan nilai, seperti di bawah minus Kolom minus Nilai variabel di-reset pada awal setiap kolom. Grup dikurangi Nilai variabel direset saat kelompok ditentukan oleh perubahan GrupGambar. Tidak ada minus Nilai variabel tidak pernah diatur ulang. Page minus Nilai variabel di-reset pada awal setiap halaman. Laporan minus Nilai variabel di-reset hanya satu kali, di awal laporan. ResetGroup Ini menentukan nama grup tempat nilai variabel di-reset, saat resetType adalah Group. Nilai untuk atribut ini adalah nama grup yang dideklarasikan dalam template laporan JRXML. Built-In Variabel Laporan Ada beberapa variabel sistem built-in, siap digunakan dalam ekspresi, sebagai berikut minus Nama Variabel dan Deskripsi Nilai variabel ini adalah nomor halaman saat ini. Ini dapat digunakan untuk menampilkan nomor halaman saat ini dan jumlah halaman yang menggunakan fitur khusus elemen bidang teks JasperReports, atribut evaluationTime. Nama variabel ini berasal dari nama grup yang sesuai dengan, yang disandikan dengan urutan COUNT. Variabel ini berisi jumlah record pada grup saat ini. Mari menambahkan variabel (countNumber) ke template laporan kami yang ada (Bab Laporan Desain). Kami akan awalan menghitung ke setiap record. Template revisi laporan (jasperreporttemplate. jrxml) adalah sebagai berikut. Simpan ke C: toolsjasperreports-5.0.1test direktori dikurangi Kode java untuk pengisian laporan tetap tidak berubah. Isi dari file C: toolsjasperreports-5.0.1testsrccomtutorialspointJasperReportFill. java adalah seperti yang diberikan di bawah ini minus Isi dari file POJO C: toolsjasperreports-5.0.1testsrccomtutorialspointDataBean. java adalah seperti yang diberikan di bawah minus Isi dari file C: toolsjasperreports-5.0. 1testsrccomtutorialspointDataBeanList. java adalah seperti yang diberikan di bawah minus Report Generation Kami akan mengkompilasi dan mengeksekusi file di atas dengan menggunakan proses build ANT reguler kami. Isi dari file build. xml (disimpan di bawah direktori C: toolsjasperreports-5.0.1test) adalah seperti yang diberikan di bawah ini. File impor - baseBuild. xml dipilih dari bab Environment Setup dan harus ditempatkan di direktori yang sama dengan build. xml. Selanjutnya, mari kita buka jendela command line dan masuk ke directory tempat build. xml diletakkan. Akhirnya, jalankan perintah ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport adalah target default) sebagai minus Sebagai hasil dari kompilasi di atas, jendela JasperViewer terbuka seperti pada layar di bawah minus Di sini, kita melihat bahwa penghitungan diawali Untuk setiap record Bagian Laporan Kami membahas struktur template laporan sederhana di bab Getting Started. Pada baris yang sama, JasperReports menyusun template laporan menjadi beberapa bagian. Bagian adalah bagian dari laporan yang memiliki ketinggian tertentu dan dapat berisi objek laporan seperti garis, persegi panjang, gambar, atau bidang teks. Mesin laporan iterates melalui catatan virtual sumber data laporan yang disediakan, pada waktu mengisi laporan. Bergantung pada setiap bagian yang didefinisikan perilaku, mesin kemudian membuat setiap bagian laporan bila sesuai. Misalnya, bagian detail diberikan untuk setiap record dalam sumber data. Saat jeda halaman terjadi, bagian header halaman dan halaman footer diberikan sesuai kebutuhan. Di JasperReports, terminologi dan bagian laporan juga disebut sebagai band laporan. Bagian terdiri dari satu atau beberapa band. Bagian ini diisi berulang kali pada waktu pembuatan laporan dan menyiapkan dokumen akhir. Bagian Utama Template laporan di JasperReports memiliki bagian utama berikut minus Tabel berikut merangkum masing-masing bagian dikurangi Tinggi bagian menentukan tinggi piksel untuk bagian tertentu dan sangat penting dalam keseluruhan rancangan laporan. Print When Expression A Boolean expression yang menentukan apakah bagian itu harus dicetak atau tidak. Split Allowed A flag yang menunjukkan apakah bagian dibiarkan terpecah bila tidak sesuai pada halaman saat ini. Jika benar, bagian itu akan ditransfer ke halaman berikutnya. Perhatikan bahwa dalam kasus, bagian tidak sesuai pada halaman berikutnya, maka bagian tersebut akan terlepas terlepas dari nilai flagnya. SplitType dapat mengambil nilai berikut minus splitTypeStretch: Splits stretched content. Jika bagian membentang pada halaman saat ini (jika ruang yang tersedia kurang dari tinggi yang dinyatakan), wilayah yang ditambahkan ke ketinggian asli diperbolehkan untuk dipecah ke halaman berikutnya. SplitTypePrevent: Mencegah perpecahan pada usaha pertama. Jika bagian tidak sesuai pada halaman berikutnya, perpecahan terjadi secara normal, karena pencegahan split band hanya efektif pada usaha split pertama. SplitTypeImmediate: Split segera. Band ini diperbolehkan untuk berpisah di mana saja kecuali di atas, elemen paling atas. Untuk mendemonstrasikan setiap bagian, mari kita tuliskan laporan template (jasperreporttemplate. jrxml). Simpan file ini ke direktori C: toolsjasperreports-5.0.1test. Dalam file ini, kami akan menampilkan teks di setiap bagian (kami bahas di atas). Isi file tersebut seperti yang diberikan di bawah ini minus Kode java untuk mengisi dan menghasilkan laporan diberikan di bawah ini. Mari simpan file ini JasperReportFill. java ke C: toolsjasperreports-5.0.1testsrccomtutorialspoint directory. Di sini, kita menggunakan sebuah instance dari JREmptyDataSource saat mengisi laporan untuk mensimulasikan sumber data dengan satu record di dalamnya, namun dengan semua field dalam record tunggal ini menjadi null. Report Generation Kami akan mengkompilasi dan mengeksekusi file di atas menggunakan proses build ANT reguler kami. Isi dari file build. xml (disimpan di bawah direktori C: toolsjasperreports-5.0.1test) adalah seperti di bawah ini. File impor - baseBuild. xml diambil dari bab Environment Setup dan harus ditempatkan di direktori yang sama dengan build. xml. Selanjutnya, mari kita buka jendela command line dan masuk ke directory tempat build. xml diletakkan. Akhirnya, jalankan perintah ant - Dmain-classcom. tutorialspoint. JasperReportFill (viewFullReport adalah target default) sebagai berikut minus Sebagai hasil dari kompilasi di atas, jendela JasperViewer terbuka seperti pada layar di bawah minus Di sini, kita dapat melihat di masing-masing 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