Thursday, June 4, 2009

How to create a pie chart in Jasper Reports?

Step1 : create a table and populate required records.

SQL> CREATE TABLE results
( party_name varchar2(30),
scored_percentage number );

SQL> INSERT INTO results VALUES ( 'UNP', 25);

SQL> INSERT INTO results VALUES ( UPFA, 60);

SQL> INSERT INTO results VALUES ( 'JVP', 5);

SQL> INSERT INTO results VALUES ( 'OTHER', 10);

Step2 : Open a new report in Jasper Report.


Step3 : Write the follwing sql query in the "report query"
select *
from results


Step4 : Drag and drop the "chart" on the summary area (i.e just after
the page footer ) and select the pie chart from the chart types.


Step5 : Right click on the chart and select "Chart Data"
set the Key expression as $F{PARTY_NAME}
Value expression as $F{SCORED_PERCENTAGE}
Label expression as
$F{PARTY_NAME}+" "+$F{SCORED_PERCENTAGE}+"%"


Step6 : Now You are done. and you will see the report preview as


Note : I've used iReport 3.1.4 here.

4 comments:

  1. how to change a alignment of key expression in pie chart and series expression in bar chart.
    And how to add one more key key expression in pie chart and series expression in bar chart.

    ReplyDelete
  2. Very helpful. The one point that had me confused was the instruction to 'drop the "chart" on the summary area'. I didn't see anything that looked like a chart! The problem was that I did not have the Palette window displayed (available in the Window menu).

    ReplyDelete
  3. මේක ලන්කාවේ වගෙ නේ??
    Very useful

    ReplyDelete