Saturday, 26 April 2014

How to add MouseOver(Tool Tip) Property to the chart in iReport

Tooltip property provide to show the value when mouse over event occur on that particular bar
To add the tooltip property open iReport, right click on the chart and select “Chart Data” (You can add also by selecting Hyperlink option)

After selection Chart Data go to Detail sections and select the Category Series, then Modify and select Item Hyperlink section and give the expression for mouse over, here in this case it will be
$F{ORDERS}.toString()   where .toString() convert Integer values to String.

Other useful links:-

Setting Default Values for Input Controls in iReport

There are multiple type of input controls in iReport which we use in reports :  -

1   1-      Text (java.lang.String)

                 Single select string input control.
                  Example: -    “India”

2   2-      Integer(java.lang.Integer)
           Single select integer input control (p_year)
           Example: -       1997

3   3-      Collection(java.util.Collection)

           Multiselect input control for string and integer values (p_shipcountry)
           Example: -  new ArrayList(Arrays.asList(new String[] {“India”,”US”}))

4   4-      Date(java.util.Date)

            Date parameter, months start from 0 to 11
             Example for 2014-04-26: - new Date(114,3,26)

5   5-      Boolean(java.lang.Boolean)

          Boolean values for true or false type values.
          Example: - “true”

Optional Where Clause in iReport Query

In this post I am going to show you how to pass optional where clause to the query in report query and will use the same query which I used to create the chart in previous post.
In this report I have three input controls, p_year (Integer), p_shipcountry(Collection) and p_shipcity(Collection).
Where p_year is a single select input control to select year means user can select only one year at a time, p_shipcountry is a Collection type input control, which is multiselect cascading input control means user can select multiple ship countries for the selected year and p_shipcity is also a Collection type multiselect cascading input control.

Query for the report:-

                 MONTHNAME(ORDERDATE) month,
                  CONCAT(MONTHNAME(ORDERDATE), RIGHT(year(ORDERDATE), 2)) monthyear,
                  COUNT(*) orders
FROM orders
WHERE (YEAR(ORDERDATE) = $P{p_year} OR $P{p_year} IS NULL)
               AND $X{IN,shipcountry,p_shipcountry}
               AND $X{IN, shipcity,p_shipcity}

In this report I have not set the default values for any input controls , so if you do not pass the value at run time by default it will show you all the values in case of Collection type input controls(p_shipcountry and p_shipcity) and for the p_year(Integer) input control you can use this expression to make optional in where clause(If you do not use this expression then you have to pass any value otherwise you will get no document page popup):-

    YEAR(ORDERDATE) = $P{p_year} OR $P{p_year} IS NULL

This means if you do not pass any value for this input control it will show you for all the years.
Now run the report and do not pass any values to parameters then you will get this chart for all the years.

Other Useful Links:-