Friday, 14 February 2020

Tip : How to remove Y1 and Y2 axis labels on dual axis chart in jaspersoft studio HTML-5(high charts) ?

Problem Statement: 
Take a look at the below snapshot. Y1 and Y2 axis's by default gets values when you plot the data on to the chart. In this tip, you would learn how to remove these values. While exploring this example, I've revisited-how to setup conditional colors to the bars. Note that this is column spline graph.



Presuming, you have already know how to set-up dual axis and how to play with advanced properties ? If not, do not worry, copy paste the jrxm provided in professional studio and play around
a) Series bucket properties for conditional colors b) Measures Advanced properties to get Y1 and Y2 axis's b) context specific advanced properties for graph's Y1 and Y2 properties.

Since it is late in the night writing this post, I didn't want just to leave the stuff that took 3-4 days of R&D,

Most of the examples in this site works on postgresql foodmart database(that ships with jaspersoft server installation) including this one.

Removing Y1 Axis Labels
This is simple and straight forward, configure below advanced property

Removing Y2 Axis Labels
There are workarounds in high charts API with opposite=false and with style-lables-enabled=false but non of these worked effectively in studio graph. lable.style.fontSize=0 is the property that removes labels from Y2 axis


Sample output
Conditional colors of bars: 
If you want to print conditional colors for bars based on series values something like below expression should work. 

In series Bucket Properties

color=$F{series}.equals("Rating1") ? "#c00000" : ($F{series}.equals("Rating2")?"#a5a5a5":($F{series}.equals("Rating3")?"#ffc000":($F{series}.equals("Rating4")?"#4472c4":"#ffffff")))
To apply the above to measures, do not forget to give below shown for each of the measure.


Other Notes:
You may also refer to this blog post for understanding how to configure Y1 and Y2 axis's advanced properties

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)

https://community.jaspersoft.com/blog/playing-advanced-properties-dual-axis-high-chart-japser-studio-6x-or-later-how-control-y-axes

JRXML: This example is developed using J.Studio 7.2 professional- preferable to use the same or later version to import this example for your studio. 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0  -->
<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="Dual Axis-Remove Y1_Y2_AxisLabels_XAxisLabelsWrapping" pageWidth="650" pageHeight="700" columnWidth="650" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="aad33c48-a3a4-4ab3-9120-761b1fe88d16">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser"/>
<property name="ireport.jasperserver.reportUnit" value="/EarthlySystems/Test/Dual_Axis_Remove_Y1_Y2_AxisLabels_XAxisLabelsWrapping"/>
<property name="ireport.jasperserver.report.resource" value="/EarthlySystems/Test/Dual_Axis_Remove_Y1_Y2_AxisLabels_XAxisLabelsWrapping_files/main_jrxml"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset1" uuid="3b042c00-14be-48c4-b1ba-b74d4cedcf22">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="328"/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="665"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<queryString language="SQL">
<![CDATA[(select 'Rating1' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category1' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category1' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category2' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category2' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category3' as category, 'Number1' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category3' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category3' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category3' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category3' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )


UNION ALL

(select 'Rating1' as series, 'category4' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category4' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category4' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category4' as category, 'Number2' As rating , 0.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category4' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category5' as category, 'Number2' As rating , 0.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category5' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category6' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category6' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category6' as category, 'Number1' As rating , 3 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category6' as category, 'Number2' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category6' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category7' as category, 'Number1' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category7' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category7' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category7' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category7' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )]]>
</queryString>
<field name="series" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="series"/>
</field>
<field name="category" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="category"/>
</field>
<field name="rating" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="rating"/>
</field>
<field name="ratingvalue" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="ratingvalue"/>
</field>
</subDataset>
<queryString language="SQL">
<![CDATA[select 1 as one from customer limit 1]]>
</queryString>
<field name="one" class="java.lang.Integer">
<property name="com.jaspersoft.studio.field.label" value="one"/>
</field>
<summary>
<band height="414">
<componentElement>
<reportElement x="0" y="0" width="650" height="414" uuid="f8096db8-7106-4544-81f4-4158678dcaee">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="ColumnSpline">
<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[""]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="legend.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="legend.enabled">
<hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.series.marker.symbol" value="diamond"/>
<hc:chartProperty name="plotOptions.series.marker.fillColor" value="#000000"/>
<hc:chartProperty name="plotOptions.column.groupPadding_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.pointPadding_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.pointPadding">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.column.pointInterval_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.series.marker.radius">
<hc:propertyExpression><![CDATA[8]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="xAxis.labels.useHTML_customSimpleMode" value="true"/>
<hc:chartProperty name="yAxis.labels.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.dataLabels.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="yAxis.labels.enabled">
<hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="xAxis.labels.step" value="1"/>
<hc:chartProperty name="xAxis.labels.style.textOverflow" value="wrap"/>
</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="labels.style.fontSize" value="0"/>
<hc:chartProperty name="linkedTo">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="max" value="3"/>
<hc:chartProperty name="min">
<hc:propertyExpression><![CDATA[0]]></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="max" value="3"/>
<hc:chartProperty name="min">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
</hc:chartSetting>
<multiAxisData>
<multiAxisDataset>
<dataset>
<datasetRun subDataset="Dataset1" uuid="aa88620b-9675-468d-b14d-e460a4523487"/>
</dataset>
</multiAxisDataset>
<dataAxis axis="Rows">
<axisLevel name="Category">
<labelExpression><![CDATA["Level Label expression"]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.String">
<bucketExpression><![CDATA[$F{category}]]></bucketExpression>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<dataAxis axis="Columns">
<axisLevel name="Series">
<labelExpression><![CDATA[]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.Comparable">
<bucketExpression><![CDATA[$F{series}]]></bucketExpression>
<bucketProperty name="color"><![CDATA[$F{series}.equals("Rating1") ? "#c00000" : ($F{series}.equals("Rating2")?"#a5a5a5":($F{series}.equals("Rating3")?"#ffc000":($F{series}.equals("Rating4")?"#4472c4":"#ffffff")))]]></bucketProperty>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<multiAxisMeasure name="Measure1" class="java.math.BigDecimal" calculation="Nothing">
<labelExpression><![CDATA[""]]></labelExpression>
<valueExpression><![CDATA[$F{ratingvalue}]]></valueExpression>
</multiAxisMeasure>
<multiAxisMeasure name="Measure2" class="java.math.BigDecimal" calculation="Nothing">
<labelExpression><![CDATA[""]]></labelExpression>
<valueExpression><![CDATA[$F{series}.equals("Rating5")?$F{ratingvalue}:null]]></valueExpression>
</multiAxisMeasure>
</multiAxisData>
<hc:series name="Measure1">
<hc:contributor name="SeriesProperty">
<hc:contributorProperty name="yAxis" valueType="Constant" value="id0"/>
</hc:contributor>
<hc:contributor name="SeriesItemProperty">
<hc:contributorProperty name="color" valueType="Bucket" value="Series.color"/>
</hc:contributor>
</hc:series>
<hc:series name="Measure2">
<hc:contributor name="SeriesProperty">
<hc:contributorProperty name="yAxis" valueType="Constant" value="id1"/>
</hc:contributor>
</hc:series>
</hc:chart>
</componentElement>
</band>
</summary>
</jasperReport>


No comments:

Post a Comment