Kritika Rana

JasperSoft: Drill Down, Anchor and Bookmark

Blog Post created by Kritika Rana on Sep 20, 2017

Introduction:

Most of the times, we struggle to navigate between reports & application for further analysis. We feel the need for more drilling between data. Today, we are going to discuss about some techniques to make our simple report to create a link within the report and outside the report.

 

So, let's get started with each of these topics one by one.

 

Drill Down

As such Jasper does not have a direct way to create any relationship between different contents. We need to use hyperlink property and some hidden parameter/property name.

Hyperlink: there are several types of hyperlink and each of them can be used for different scopes. The built-in types provided by Jasper Reports are: Reference, Local Anchor, Local Page, Remote Anchor and Remote Page. Image, text field and chart elements can be used both as anchors into a document and as hypertext links to external sources or local anchors.

Based on the type of drill functionality, we have divided them in three different categories where we will be learning these.

1) Drilling down to CA PPM Url   

     Link Target: Blank or Self

     Link Type: Reference

     Hyperlink Refrence Expression: $Clarity_App_Dynamic_Url 

2) Drill down to execute Jaspersoft report

      a) By Using Hyperlink and Embeded HTTP API - This Method is similar to that of above, however it involves          jaspersoft report execution inside clarity html portlet and then finally calling that as a clarity url similar to that of          above.

      b) By Using Hyperlink and Hyperlink Parameter method-    

            Link Target: Blank or Self

            Link Type: ReportExecution

            Parameter: _report Parameter is imported and we need to pass report execution path (JasperServer reference             path) and other Parameters based on input control which you have to pass as shown below:

 

3) Drill down in chart to execute Jaspersoft report

Similar to above option chart also have hyperlink which can be use to execute report and passing other parameters.

To create hyperlinks:

With new HTML5 charts (Highcharts) functionality added to JasperReports, including a hyperlink in a chart is different to JFreeCharts (regular Charts) and Fusion charts (Charts Pro).

Note: Hyperlink on a whole chart is not yet supported.

  1. Go to Chart Properties > Chart Data > Data Axes.
  2. Double click "Category_name".
  3. Click the Properties tab. The Add/modify property dialog appears.

  4. Create a property named url. Add the expression:

    “http://www.ask.com/web?q=” + F{shipcountry}
  5. Click OK.
  6. Double-click the measure Total Orders.
  7. Click the Advanced Properties tab.
  8. Click Add. The Add/modify property dialog appears.

     
  9. Click the down arrow and choose Built-In Hyperlink Property. Close that window.
  10. Click the Hyperlink button. That provides a shortcut to the two most important properties needed to create a hyperlink.
  11. Double-click hyperlinkReference (SeriesItemHyperlink). The Add/modify property dialog opens with some information filled in. You customize this information to the values you need.
  12. Click the radio button for Use a bucket property value and type Country.url. Click OK. 
  13. Save and preview your report. In the HTML preview, if you click the bar for any country, you will be taken to the Ask.com page for that country.

For instructions not based on the examples in this article, use the following procedure:

Note: Bucket-level properties are the only place where you can create expressions to be used with your link. If you are not using an expression, you must either use static values or reference a bucket level property.

  1. Identify the series you want to use for your link.
  2. Create a bucket property for that series. i.e. If you are using a pie chart, the category bucket may have a property called myUrlwhich contains your url built with the category value.
    This can be done in Edit Chart Properties > Chart Data > Data Axes > Categories
  3. Identify the measure to which you need to add a link.
    This can be done in Edit Chart Properties > Chart Data > Data Axes > Measures
  4. In the advanced properties of your measure click Hyperlink.
    This will create for you a couple of properties. Edit them by assigning the proper value (again, here you'll have to either use static values or reference a bucket level property).

To add a ReportExecution hyperlink:

If you want a ReportExecution hyperlink, you need to renme one of the measure's advanced properties (see step 4 in the previous procedure) to _reportand enter the corresponding value, and if you need to pass parameter values you will also need to add them as measure properties.

  • shoud be Built-in Hyperlink Property with constant value of ReportExecution
  • hyperlinkTargetshoud be Built-in Hyperlink Property with constant value of Blank.
  • _reportshould point to a report, i.e. /reports/samples/EmployeeAccountsAnchor & Bookmark  

Anchor  

Anchor create an relationship link inside the current/Remote document for movement; it is only available for elements that support hyperlinks (textfield, image, and chart). <anchorNameExpression> tag transforms that particular text field or image into a local anchor of the resulting document, to which hyperlinks can point. The anchor will bear the name returned after evaluation of the anchor name expression.

Example of Local Anchor

1) Create a local Anchor expression

2) Create a link expression in different band

3) Test working of Anchor by Report preview

 

Bookmarks 

Some of the document formats, such as PDF, have built-in support for tables of contents and bookmarks. To allow you to make use of this, JasperReports lets you transform anchors into document bookmarks. To be used as bookmarks, anchors should have an indentation level set. To do this, set a positive integer value for the bookmarkLevel attribute available for all hyperlink elements in JasperReports.

 

1) Set Anchor Name and Bookmark Level as shown below

<title>

              <band height="739" splitType="Stretch">

                     <frame>

                           <reportElement x="0" y="0" width="555" height="739" uuid="90cd3f3d-a3e2-4993-b643-c14ce7185863"/>

                           <frame>

                                  <reportElement positionType="Float" x="10" y="10" width="250" height="70" uuid="a343ca21-13f5-4930-a727-00bb63ff155a"/>

                                  <textField bookmarkLevel="1">

                                         <reportElement x="0" y="0" width="102" height="30" uuid="a4208b98-6de4-42fb-ac6d-962b43e5eacf"/>

                                         <textFieldExpression><![CDATA["TextField1"]]></textFieldExpression>

                                         <anchorNameExpression><![CDATA["Bookmark1"]]></anchorNameExpression>

                                  </textField>

                                  <textField bookmarkLevel="2">

                                         <reportElement x="100" y="27" width="102" height="30" uuid="47db2800-106f-4468-80fa-a20d5297e333"/>

                                         <textFieldExpression><![CDATA["TextField1.1"]]></textFieldExpression>

                                         <anchorNameExpression><![CDATA["Bookmark1.1"]]></anchorNameExpression>

                                  </textField>

                           </frame>

                           <frame>

                                  <reportElement positionType="Float" x="60" y="110" width="410" height="65" uuid="807b05dc-aa1f-4a3a-a2d9-f99325df01fc"/>

                                  <textField evaluationTime="Report" bookmarkLevel="1">

                                         <reportElement x="0" y="0" width="106" height="30" uuid="44910538-5fae-4fb0-a393-e1137375ed6f"/>

                                         <textFieldExpression><![CDATA["TextField2"]]></textFieldExpression>

                                         <anchorNameExpression><![CDATA["Bookmark2"]]></anchorNameExpression>

                                  </textField>

                                  <textField evaluationTime="Report" bookmarkLevel="2">

                                         <reportElement x="280" y="17" width="106" height="30" uuid="6266e280-8f7d-4316-9a74-dc6ec88cbfb3"/>

                                         <textFieldExpression><![CDATA["TextField2.1"]]></textFieldExpression>

                                         <anchorNameExpression><![CDATA["Bookmark2.1"]]></anchorNameExpression>

                                  </textField>

                           </frame>

                     </frame>

              </band>

       </title>

2) Set PDF export property for bookmark as

<property name="net.sf.jasperreports.export.pdf.create.batch.mode.bookmarks" value="true"/>

Output:

 

Stay connected for next blog on combined and complicated charts in Jasper.

Outcomes