Adjust alignment of label to right and fix label truncating issue in stacked bar chart

Adjust alignment of label to right and fix label truncating issue in stacked bar chart

Softwares:

Jasper Server 5.6.0
IReport 5.6.0

Now we will see how to work on Lables Alignment and fix truncating in Stacked Bar Chart

First create a sample report which includes Stacked Bar Chart

Report Output in Jasper Server as follows

OriginalOutputt

Expected Output in Jasper Server as follows

ExpectedOutput

In order to achieve Expected Output,write custom code in java and include below lines of code:

For Label Alignment include below line

 plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

For avoid truncating Labels include below line

  categoryAxis.setMaximumCategoryLabelWidthRatio(3.0F);

Create jar file of the java code and add it in chart customiser property of chart in the format: ‘packagename.classname’ as follows:-
Refer the screenshot:

ChartCustomzeer

Publish the Report,and add the Jar for the Report which had published
Right Click on the Report –>Edit

EditJaar

Control Resources –>Add Resource–>Upload Jar

UploadJar

Give a valid name and then Submit

Execute the Report and output as follows

ExpectedResult

Thanks,
Satya Gopi,
BI Developer

Groovy

Groovy Language

  • Groovy can run on JVM
  • Groovy scripts can be executed using groovy jar file.
  • Annotations are supported in groovy.

Groovy installation.

  • Binary download link http://www.groovy-lang.org/download.html
  • The binary can be run from command prompt
  • Set GROOVY_HOME, GROOVY_HOME\bin variable as enviroment variable.
  • After installing and running in the command line you get the groovy shell(groovysh).
  • groovy> println ” hello helical”

Source code in groovy.

  • The extension for groovy source file is .groovy
  • We can write either script or we may also encapsulate the code as class definition inside this file.
  • By default groovy class is subclassed by java.lang.Object.
  • Java class and its objects can access groovy script class and object and vice versa.
  • Using groovyc we can compile the source code.
  • Plain Old Groovy Objects (POGO).

Intersting facts about groovy.

  • Groovy doesnot require ; at the end of statement.
  • Last expression of the method is returned by default. So we may not explicitly use return keyword.
  • Maps, list and regular expression readily available in groovy.
  • The following package are readily available. (groovy.lang.*, groovy.util.* , java.lang.*, j ava.util.*, java.net.*, java.io.*, java.math.BigInteger, java.math.BigDecimal)
  • Its classes and methods are by-default public
  • Automatic getter and setter is created for the fields in groovy class.
  • Unlike java == operator in groovy checks for contents.
  • The is() may be used to check if two variables/object refer the same.
  • The parameters inside a function are optional.
  • Gpath is expression language to evaluate nested structure.

Data types in Groovy.

    • The keyword def is used to define variable. We can also use specific type for variable declaration. Example int marks, String company. etc
    • Range data type is a Collection. Ranges consists of two values separated by two dots.
for (i in 0..9) {
  println ("Hello $i")
}

assert 'L'..'P' == ['L', 'M', 'N', 'O','P']

String & Gstring.

  • ‘Strings may be enclosed inside single quote ‘.
  • “Mehod() calls and ${variable} substitution inside a string is known as Gstring”.
  • ”’Tripple single quotes can be used for multi line string”’
  • “”” Multi line Gstring can be enclosed in tripple quotes”””
  • /regularexpression/

Methods in Groovy.

  • Groovy supports operator overloading. – operator can be used to substract string, << can be used for string concatination.
  • Groovy string has .toUrl() method that can be directly used to convert a string to Url encoding string.

 

 

package packageName
class ClassName {
  static void main(def args){
    def hetroList= [1,2,"hi","45"]
    hetroList.each{ println it }
  }
} 

Deploy jar file in jasperserver without restarting service

Option 1 – If you want to use your Jar in a several reports.

You should “Add Jar” (as it called in iReport repository manager) to some folder in the Jasper Server folder tree. Then “Add reference” to this resource in Resources section of you specific report.

Option 2 – You need a jar in a specific report.

Use “Add Jar” option in a resources section of specific report.

Worked perfectly on JasperServer 4.7

 

Naveen Dasari

Helical IT Solutions