Amazon festival offer

Monday, 8 September 2014

Add customizer class to remove Bar Gab between two series of Ba Chart

In This post I will see how to add a customizer class to remove space between two series of bar chart. 

Desired output after adding customizer class.

To get this output we have to create a executable jar file. Will use Netbeans to create .jar file.

Step 1:- Open NetBeans and create a new Java Application project.

Give a Project Name – customizerbargap   (you can give any other name also)
Here you can see the project location and class name, you can also change these parameters.
My Main class name CustomizerBarGap
and Finish

Copy below code in

package customizerbargap;

import net.sf.jasperreports.engine.JRAbstractChartCustomizer;
import net.sf.jasperreports.engine.JRChart;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;

public class CustomizerBarGap extends JRAbstractChartCustomizer {

public void customize(JFreeChart chart, JRChart jasperChart) {

CategoryPlot categoryPlot = chart.getCategoryPlot();
BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

//Spaces between bars

Add required jars in Library folder like Jfree.jar, Jcommon.jar, Jasperreports.jar
Right click on the project  and click on Clean and Build.
In output window you can find the path of .jar file

In my case it is –
Building jar: C:\Users\sharad\Documents\NetBeansProjects\Project_Name \dist\ Package_Name(CustomizerBarGap).jar

Open iReport and add CustomizerBarGap.jar in the Classpath.
To go add go to Tools --> Options --> ClassPath --> Click on Add JAR.

After adding .jar file click on the chart and go to Bar Chart - Properties section and set Customizer Class property to PackageName.ClassName  i.e.

Customizer Class =  customizerbargap.CustomizerBarGap

Then click on the Preview tab.

Saturday, 24 May 2014

How to install iReport in Linux machine

In this post you will see how to install iReport in Linux machine.

1:- First check out which version of iReport you want to install, to see the iReport versions you can use bellow link.
Now download iReport-5.5.1.tar.gz from bellow link 

2:- After downloading iReport go to the directory where you have downloaded it. In my case it is in Downloads directory.
$ cd /Downloads/
And if you want to copy in other directory you can use mv (move) or cp (copy) command.
$ mv/Downloads/ iReport-5.5.1.tar.gz     /opt/ iReport-5.5.1.tar.gz

3:- Extract iReport-5.5.1 directory from zipped file using bellow command.
$ tar -zxvf iReport-5.5.1.tar.gz

  1. -z : Work on gzip compression automatically when reading archives.
  2. -x : Extract archives.
  3. -v : Produce verbose output i.e. display progress and extracted file list on screen.
  4. -f : Read the archive from the archive to the specified file. In this example, read backups.tar.gz archive.
  5. -t : List the files in the archive.
4:- Now to start iReport open a terminal and type the bellow command.

$ /Downloads/iReport-5.5.1/bin/ireport

Now if your iReport starts that means you have successfully installed iReport.

Thursday, 22 May 2014

Adding ‘All’ in JasperReport input control query and passing 'All' as parameter

In this post you will see how to append ‘All’ keyword in JasperReport input control query and passing 'All' as parameter.

Now the question is where we can use this trick in report, I saw a question in forum where user wanted to append ‘All’ with other input control values so user can also select ‘All’ to select all the values of that input control instead of selecting manually  all the values.

In the case of multiselect parameter of Collection type (java.util.Collection)  you do not need to give "All" to select all the values in iReport as default value for that parameter by default it means all the values are selected.

But if the parameter is single select of String type then the query for input control will be: -

iReport query will be : - 
FROM orders
WHERE ($P{p_shipcountry}='All' OR SHIPCOUNTRY=$P{p_shipcountry})
Where p_shipcountry is a parameter in iReport and it is single select of String (java.lang.String) type parameter.

Monday, 19 May 2014

Defining a variable in SQL SELECT statement in iReport

In this blog you will see how to define a variable in SQL SELECT statement and use that variable to do the calculations for other computed values.

Defining variables in MySQL or in other database is easy but defining variable in iReport is totally different.
I show you both way how to define variable in MySQL SELECT statement and in iReport.

Defining variable in MySQL: -

SET @tsum := 0;
SELECT SUM(@tsum := @tsum + ProfitTotal) as Cumulative,
       SUM(profit) as ProfitTotal
FROM table_name

Defining a variable in iReport : -

SELECT SUM(@tsum := @tsum + ProfitTotal) as Cumulative
    (SELECT  profitTotal, @tsum :=0
     FROM table_name ) a

As you can see first I have defined the variable in inner select statement then you can sum up in the outer select statement.