Jaspersoft BI Tools

iReport,Jaspersoft Design Studio,Jaspersoft Server, Schema Workbench,Analysis,Dashboards, Self Service BI, Domains,Topics,Ad-Hoc Reports, Jaspersoft ETL, Embedding BI,HTML-5 charts, Fusion Charts,JFree Charts,Drill down reports , Drill down Dashboards,Visualize.js, Performance Tuning, D3 Charts, Jaspersoft Customization

Tuesday, January 19, 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>