Friday 29 January 2016

Donut and Semi donut high charts (HTML-5) in Jasper Design Studio 6.x (or) How to convert semi pie or pie to semi donut or semi pie chart

Hi Folks,

As of Jasper 6.2 we do not have donut and semi donut high chart visualizations in it.

Using the available semi pie/circular chart and pie chart, we can convert them into semi donut and donut visualizations.
Kindly note that, this post will not tech you how to work with html-5 scripting but will tech you how to grab the properties from highcharts API and make use of them in Jasper Design Studio.

For doing it, we need to add series.innerSize=80% property in "Advanced properties section of both charts. (don't tick the check box).

Example works only in professional studio
Current example tested on : J.D.Studio Pro 6.2 and J.S 6.2 Pro .

NOTE : Click the images to get the best view of the content on them.
*** Sample output of the tip ***


1) Properties set on semi circular chart.

2) Properties set on pie chart


 I have also played with few other advanced and simple properties of semi circular & pie chart and would like to share the purpose of property and how the end use get benefited from it.

You can find all the properties in above two images. 

1) Selection of Slice (Slice will be separated from center) - This is useful for drill down reports - End user can easily understand on which slice he/she clicked.
2) Slice and Label connector line color (By default the chart will take the slice/sector color)
3) Slice shadow on hovering - (Build in property - tick the Show Showdow property from "Plot Options for Series")
4) Change the cursor Style when mouse hovered (better look and feel for the end user if it is a drill down parent report)
5) Percentages as labels.
6) Percentage and Value in Tool tip.
7) Title of Chart in middle of chart (Change X=0 and Y=0 in Chart title properties)


JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-29T01:49:52 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="SemiCircularChart" pageWidth="12000" pageHeight="842" columnWidth="11960" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5d646afa-9cdc-41f7-aa48-8d901762ed99">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <property name="ireport.jasperserver.url" value="http://localhost:8081/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/Reports/Semi_Donut_and_Donut_Chart_Examples_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/Reports/Semi_Donut_and_Donut_Chart_Examples"/>
    <property name="net.sf.jasperreports.export.pdf.encrypted" value="true"/>
    <queryString>
        <![CDATA[SELECT member_card,SUM(num_cars_owned) FROM customer GROUP BY member_card]]>
    </queryString>
    <field name="member_card" class="java.lang.String"/>
    <field name="sum" class="java.lang.Long"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="31" splitType="Stretch"/>
    </title>
    <summary>
        <band height="329" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="329" uuid="f42805af-d872-4e9b-be4d-f29ede7935fe"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="SemiPie">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="series.innerSize" value="70%"/>
                        <hc:chartProperty name="title.style.color">
                            <hc:propertyExpression><![CDATA[new java.awt.Color(-16111803)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.style.fontSize">
                            <hc:propertyExpression><![CDATA["12px"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA["Member Card Wise Cars"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.verticalAlign">
                            <hc:propertyExpression><![CDATA["middle"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.y">
                            <hc:propertyExpression><![CDATA[new Integer(40)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="chart.backgroundColor">
                            <hc:propertyExpression><![CDATA[new java.awt.Color(-855822)]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{member_card}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Number Of Cars : "]]></labelExpression>
                            <valueExpression><![CDATA[$F{sum}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1"/>
                </hc:chart>
            </componentElement>
            <componentElement>
                <reportElement x="600" y="0" width="435" height="329" uuid="ee3464c8-c006-4cd9-abb7-f77b32ae46a9"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Pie">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.backgroundColor">
                            <hc:propertyExpression><![CDATA[new java.awt.Color(-855822)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="chart.type" value="pie"/>
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.pie.cursor" value="pointer"/>
                        <hc:chartProperty name="plotOptions.pie.dataLabels.connectorColor" value="yellow"/>
                        <hc:chartProperty name="plotOptions.pie.dataLabels.enabled" value="false"/>
                        <hc:chartProperty name="plotOptions.pie.dataLabels.format">
                            <hc:propertyExpression><![CDATA[" {point.percentage:.1f} %"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.pie.showInLegend" value="true"/>
                        <hc:chartProperty name="plotOptions.series.allowPointSelect">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.showCheckBox">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="series.innerSize" value="80%"/>
                        <hc:chartProperty name="title.style.color">
                            <hc:propertyExpression><![CDATA[new java.awt.Color(-16369815)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.style.fontSize">
                            <hc:propertyExpression><![CDATA["12px"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA["NO.Of.Cars"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.verticalAlign">
                            <hc:propertyExpression><![CDATA["middle"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.y">
                            <hc:propertyExpression><![CDATA[new Integer(0)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="tooltip.pointFormat">
                            <hc:propertyExpression><![CDATA["{series.name}: <b>{point.percentage:.1f}%</b>" +"("+$F{sum}+")"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="tooltip.shared">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="tooltip.useHTML">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{member_card}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["No.Of Cars"]]></labelExpression>
                            <valueExpression><![CDATA[$F{sum}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1"/>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>
 

References : 
http://www.highcharts.com/demo/pie-semi-circle

Wednesday 27 January 2016

Tip : How to enable high charts category axis (X-axis) and value axis (Y-axis) line colors in Jasper Design Studio 6.x or later ?

Hi Folks,

This post will give you the tip of setting Advanced properties to display the Category Axis (X-axis), Value Axis(Y-axis) in HighCharts of Jasper Design Studio.

Software Used for this example : 
1) Jasper Design Studio 6.2 Professional
2) Jasper Server 6.2 Professional
3) Foodmart database of PostgreSQL .

1) Click on Advanced properties of Chart and Click on Add to add below shown properties.
2) Properties : 
xAxis.lineColor = #008000 (check box disabled)
xAxis.lineWidth = new Integer(2) (check box enabled)
yAxis.lineColor = #FF0000 (check box disabled)
yAxis.line.Width= new Integer(1) (check box enabled)


3) Sample output in Server: 
Reference : 
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/yaxis/linecolor/

JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-27T13:59:59 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Statcked Bar With LIne" pageWidth="800" pageHeight="842" columnWidth="760" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5d0254fd-0a3b-4d5d-8e26-3c4b6c618d0f">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="ireport.jasperserver.url" value="http://localhost:8081/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/Reports/Bar_Chart_X_axis_and_Y_axis_Line_Color_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/Reports/Bar_Chart_X_axis_and_Y_axis_Line_Color"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <queryString>
        <![CDATA[SELECT occupation,member_card,SUM(num_cars_owned) cars,SUM(total_children) children
 FROM customer GROUP BY occupation ,member_card
order by occupation ,member_card]]>
    </queryString>
    <field name="occupation" class="java.lang.String"/>
    <field name="member_card" class="java.lang.String"/>
    <field name="cars" class="java.lang.Long"/>
    <field name="children" class="java.lang.Long"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="350" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            <componentElement>
                <reportElement x="0" y="0" width="760" height="350" uuid="fb580735-8c78-4008-93aa-2bd2bc6ed227"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Column">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="colors">
                            <hc:propertyExpression><![CDATA[java.util.Arrays.asList("#7cb5ec","#434348","#90ed7d","#f7a35c","#008000","#f15c80","#e4d354","#2b908f","#f45b5b","#91e8e1")]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="xAxis.lineColor" value="#008000"/>
                        <hc:chartProperty name="xAxis.lineWidth">
                            <hc:propertyExpression><![CDATA[new Integer(2)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.lineColor" value="#FF0000"/>
                        <hc:chartProperty name="yAxis.lineWidth">
                            <hc:propertyExpression><![CDATA[new Integer(2)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA["Number Of Cars"]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{occupation}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns"/>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="Sum">
                            <labelExpression><![CDATA["Number Of Cars : "]]></labelExpression>
                            <valueExpression><![CDATA[$F{cars}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1"/>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>
 

Tuesday 19 January 2016

Playing with Advanced Properties of Dual Axis high Chart in Japser Studio 6.x or later - How to control Y axes values (min or max or common zero)

Hi Folks,

In my previous post, I wrote on how to work with StackedColumn..Line high chart in Jasper Studio 6.x. which you can find it  here 

This post is an extension of above example and gives you the tips for below points.

Example tested on :
1) Jasper Design Studio 6.2 & Server 6.2 - both are Professional editions.
2) foodmart database - PostgreSQL server. 

Problem Statement : 
How to set min and max values for Y1-axis and Y2-axis ? (Or)
How to tell Y2-axis to use the same values of Y1-axis ?  (Or)
How to tell both the axes to start with a common value ( a start point of zero) ?

You will find only the core part for this. 

1) Right Click on Chart (StackedColumn..Line)
2) Right bottom corner click on "Show Advanced Properties" 
3) Among the 3 tabs be in "Chart Properties" tab and inside it click "Context Specific" tab. 


4)  As shown in above image, click on "Add" button and below mentioned properties 
 Y1-Axis Properties (Default Axis for Dual Axis Chart)
# Name = yAxis
# Bydefault _jrAxisIndex attribute populates, and default value is 0
(If you have multiple axes you should give different default value say 1 or 2 or 3 for Y-axis2, Y-axis3, Y-axis4 repsectively).
 # This axis will take a mandatory property which would be used to identify the axis - later in the chart in some other place(Will discuss in next point)
   id="id0"
# Give properties like min, max, title.text and etc taking from HighCharts API. 
    High Charts API reference : http://api.highcharts.com/highcharts#yAxis
 
 

5) Repeat point-4 for second Y-axis (i.e., Y2-Axis) 
 The property linkedTo=0 will link axis values  properties from Y1-axis to Y2-Axis.

6) Go to each measure from configuration and click on modify to add advanced properties 

Measure 1: Store Sales
Contributor= SeriesProperty
Name=yAxis
Use constant Value =id0 (with out double quotes).

Do the same for remaining measures

Measure 2: Unit Sales
Contributor= SeriesProperty
Name=yAxis
Use constant Value =id0 (with out double quotes).

Measure 3:
Contributor= SeriesProperty
Name=yAxis
Use constant Value =id1 (with out double quotes).

 

Sample output (With the above explained properties). 

JRXML : 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-19T18:18:11 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4_3" pageWidth="700" pageHeight="842" columnWidth="660" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3a9c4e03-faeb-4a1e-b0b6-4eb2dcdd5af0">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="ireport.jasperserver.url" value="http://localhost:8081/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/Stacked_Bar_with_Line_Sample"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/Stacked_Bar_with_Line_Sample_files/main_jrxml"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <queryString>
        <![CDATA[SELECT DISTINCT c.occupation,t.the_month,t.month_of_year,sum(sf7.store_sales) store_sales,sum(sf7.unit_sales) unit_sales FROM customer c
INNER JOIN sales_fact_1997 sf7 ON c.customer_id=sf7.customer_id
INNER JOIN time_by_day t ON t.time_id=sf7.time_id
WHERE t.the_year=2012
GROUP BY c.occupation,t.the_month,t.month_of_year
ORDER BY t.month_of_year]]>
    </queryString>
    <field name="occupation" class="java.lang.String"/>
    <field name="the_month" class="java.lang.String"/>
    <field name="month_of_year" class="java.lang.Integer"/>
    <field name="store_sales" class="java.math.BigDecimal"/>
    <field name="unit_sales" class="java.math.BigDecimal"/>
    <title>
        <band height="50"/>
    </title>
    <summary>
        <band height="449" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="660" height="449" uuid="6dd6cf77-5197-46b5-9691-8fd27d40b95d"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="StackedColumnLine">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="colors">
                            <hc:propertyExpression><![CDATA[java.util.Arrays.asList("#7cb5ec","#434348","#FF0000","#f7a35c","#8085e9","#f15c80","#e4d354","#2b908f","#f45b5b","#91e8e1")]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.allowPointSelect">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dashStyle">
                            <hc:propertyExpression><![CDATA["Dash"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA["Stacked Column and Line - Dual Axis Chart"]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <hc:chartSetting name="yAxis">
                        <hc:chartProperty name="_jrAxisIndex">
                            <hc:propertyExpression><![CDATA[1]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="id">
                            <hc:propertyExpression><![CDATA["id1"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="linkedTo">
                            <hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="min">
                            <hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA["Profit"]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <hc:chartSetting name="yAxis">
                        <hc:chartProperty name="_jrAxisIndex" value="0"/>
                        <hc:chartProperty name="id">
                            <hc:propertyExpression><![CDATA["id0"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="min">
                            <hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA["Unit and Store Sales"]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Month">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket order="None" class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{the_month}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns"/>
                        <multiAxisMeasure name="Store Sales" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Store Sales"]]></labelExpression>
                            <valueExpression><![CDATA[$F{store_sales}]]></valueExpression>
                        </multiAxisMeasure>
                        <multiAxisMeasure name="Unit Sales" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Unit Sales"]]></labelExpression>
                            <valueExpression><![CDATA[$F{unit_sales}]]></valueExpression>
                        </multiAxisMeasure>
                        <multiAxisMeasure name="Profit" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Profit"]]></labelExpression>
                            <valueExpression><![CDATA[$F{store_sales}.intValue() -$F{unit_sales}.intValue()]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Store Sales">
                        <hc:contributor name="SeriesProperty">
                            <hc:contributorProperty name="yAxis" valueType="Constant" value="id0"/>
                        </hc:contributor>
                    </hc:series>
                    <hc:series name="Unit Sales">
                        <hc:contributor name="SeriesProperty">
                            <hc:contributorProperty name="yAxis" valueType="Constant" value="id0"/>
                        </hc:contributor>
                    </hc:series>
                    <hc:series name="Profit">
                        <hc:contributor name="SeriesProperty">
                            <hc:contributorProperty name="yAxis" valueType="Constant" value="id1"/>
                        </hc:contributor>
                    </hc:series>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>
 

Thursday 14 January 2016

StackedColumnLine or StackedColumn..SpLine highcharts example in Jasper Design Studio 6.x or later

Hi Folks,

This tutorial will talk about how to work with StackedCoulumnLine or StackedColumn..SpLine

Software used for this example
1) Jasper Design Studio 6.2 Professional
2) Jasper Server 6.2 Professional
3) PostgreSQL foodmart database

Chart engine implementations vary from tool to tool to visualize data on graphs hence we have to build our result set from querying technologies to adapt it by the graph.


Core parts:

Query Format : 
In jasper your query format for dual axis (Stacked bar + Line) should take below query format. 
i.e., the chart will take 3 measures . In this example I have taken 2 measures and caluculated 3rd mesure as profit by using first 2 measures.

 Graph to pull on Designer
  Drag and drop the StackedColumnLine or StackedCo..Spline chart and give chart data properties as shown in below two images. 
 

Chart Properties to Set :

Sample output in the server : 
Publish it the server and view the output. Sample output will look as shown in below image. 
 JRXML : 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-14T14:36:04 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4_3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3a9c4e03-faeb-4a1e-b0b6-4eb2dcdd5af0">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="ireport.jasperserver.url" value="http://localhost:8081/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/Reports/Stacked_Bar_with_Line_Sample"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/Reports/Stacked_Bar_with_Line_Sample_files/main_jrxml"/>
    <queryString>
        <![CDATA[SELECT DISTINCT c.occupation,t.the_month,t.month_of_year,sum(sf7.store_sales) store_sales,sum(sf7.unit_sales) unit_sales FROM customer c
INNER JOIN sales_fact_1997 sf7 ON c.customer_id=sf7.customer_id
INNER JOIN time_by_day t ON t.time_id=sf7.time_id
WHERE t.the_year=2012
GROUP BY c.occupation,t.the_month,t.month_of_year
ORDER BY t.month_of_year]]>
    </queryString>
    <field name="occupation" class="java.lang.String"/>
    <field name="the_month" class="java.lang.String"/>
    <field name="month_of_year" class="java.lang.Integer"/>
    <field name="store_sales" class="java.math.BigDecimal"/>
    <field name="unit_sales" class="java.math.BigDecimal"/>
    <title>
        <band height="50"/>
    </title>
    <summary>
        <band height="314" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="314" uuid="6dd6cf77-5197-46b5-9691-8fd27d40b95d"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="StackedColumnLine">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Month">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket order="None" class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{the_month}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns"/>
                        <multiAxisMeasure name="Store Sales" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Store Sales"]]></labelExpression>
                            <valueExpression><![CDATA[$F{store_sales}]]></valueExpression>
                        </multiAxisMeasure>
                        <multiAxisMeasure name="Unit Sales" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Unit Sales"]]></labelExpression>
                            <valueExpression><![CDATA[$F{unit_sales}]]></valueExpression>
                        </multiAxisMeasure>
                        <multiAxisMeasure name="Profit" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Profit"]]></labelExpression>
                            <valueExpression><![CDATA[$F{store_sales}.intValue() -$F{unit_sales}.intValue()]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Store Sales"/>
                    <hc:series name="Unit Sales"/>
                    <hc:series name="Profit"/>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>
 

Tuesday 12 January 2016

Scriptlet Example in Jaspersoft 6.x for begineers - Hello World Sample Example

Hi Folks,
This tutorial talks about step by step procedure to write a custom Scriptlet in Jasper Design Studio

Environment : 
Jasper Design Studio 6.2 Professional ,
Eclipse Mars.1 Release (4.5.1)

Aim of the tutorial : Print "Hello..." information on summary band. 
1) Choose your Java Editor 
        (I have taken Eclipse for this tutorial user friendly for Eclipse
            - Netbeans is developer friendly for iReport Designer)

2) Create Java Project 
     File -> New -> Project -> Java Project -> Give Project Name as "Test"

3) Add Jasper Server jar file to Project Path
Right click on Project Name -> Build Path ->Configure Build Path -> Libraries -> Add External Jar Files -> Locate the jar file from below location -> Click on Apply -> OK
   Location of Jar File : 
      C:\Jaspersoft\jasperreports-server-6.2.0\apache-tomcat\webapps\jasperserver-pro\WEB-INF\lib
   Jar File Name : jasperreports-pro-6.0.0.jar

4)  Create a Package & a Class inside it with your business logic

Package name is : com.sadakar.jasper
Class Name is : Test4

package com.sadakar.jasper;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;

public class Test4 extends JRDefaultScriptlet{

    public String hello() throws JRScriptletException
    {
        return "Hello! I'm the report's scriptlet object.";
    }
}





NOTE :
 Scriplets can be written using  JRDefaultScriptlet  and  JRAbstractScriptlet
The current example is a user defined scriptlet hence it should import JRDefaultScriptlet
More information can be found at : http://jasperreports.sourceforge.net/sample.reference/scriptlet/

We can not run  the class as Java Application. To run it as a Java Application it requires main() method.

5) Make the Project as Jar File (Export the project as a Jar File)
Right click on the "Test" Project -> Export -> Java (JAR File). 
 I have given jar file name as "test"

6) Make use of Custom Java Code from the exported Jar File in Studio  - How ?  

a) Put the Jar in Studio Project Path 
   Right Click on "My Reports" Project -> Build Path -> Configure Build Path -> Libraries -> Add External Libraries ->("test" jar from your exported location from Eclipse) ->

b) Creating a sample JRXML to test the hello() method from the JAVA Code
     i) Create a JRXML
     ii) Remove unnecessary bands
     iii) Go to "Scriptlets" section from "Outline" window
     iv) Right Click on "Scriplets" and then  click on "Create Scriptlet"
     v) Give Name="Hello" and Class="com.sadakar.jasper.Test4"  (with out double quotes).
     vi) Observe that as quick as you create Scriptlet, Jasper Studio engine creates a parameter
           in  "Parameters" node. Here it will create "Hello_SCRIPTLET"
     vi) Now, call the hello() method anywhere in the report
           Drag a "Text Filed" to the summary and write this expression
                                            $P{Hello_SCRIPTLET}.hello()


 NOTE : If you don't use any data source to the report select No Data Type = "All sections No Detail" to the report in its properties

 7) Save , Compile and run the report. 




Download Examples : 
JRXML+JAR File + Complete Eclipse Project 

I hope this helps some one to get start with scriptlets in jasper

References : 
http://jasperreports.sourceforge.net/sample.reference/scriptlet/
http://blog.sacaluta.com/2007/07/jasperreports-scriptlet-example.html