Creating Hyperlinks in HTML5 Charts

Creating Hyperlinks in HTML5 Charts

To follow a link in an HTML 5 chart, the user clicks a chart component that represents a measure. This hyperlink is created by a specific extension to that chart component, which evaluates properties of the measure. You can create hyperlinks in two ways:

Use simple configuration to create hyperlinks that are automatically bucketed by the category in a simple chart.
Use advanced configuration to create more complex values for a hyperlink. To do this, you define a bucket property, a key/value pair associated with a category or series level, and then define the hyperlink value using an expression.

This example shows how to combine a URL with a hidden measure to create an interesting user experience.

Creating a Simple Hyperlink

Create the report:

1. Create a new report:
a. Choose a blank template and click Next.
b. Set a name and location for the report and click Next.
c. Select the Sample DB data adapter and click Next.
d. Enter the following query:

select * from orders

e. On the Fields page, select all fields and click Finish.

Add a column chart:

1. Add the HTML5 Charts element to the title band and select Column.
2. Select the Data Configuration tab.
3. For the Category Expression section:
a. Enter $F{SHIPCOUNTRY} for the Category Expression.
b. Verify that Ordering is set to Ascending.
4. For the Series section, use the following settings:
a. Series: Series 1
b. Value Expression: $F{ORDERID}
c. Aggregation Function: DistinctCount
d. Tooltip Expression: "Number of Orders"

At this point the chart is configured. You can click Show Chart Preview to preview it from the dialog.

Configure a simple hyperlink:

1. On the Data Configuration tab, click Edit Hyperlink.

The Edit Hyperlink information dialog box is displayed.

Editing the Number of Orders a Second Time

2. Click Use Hyperlink and enter the following information:
     Hyperlink Target – Top
     Hyperlink Type – Reference
     Hyperlink Reference Expression"http://google.com/#q=" + $F{SHIPCOUNTRY}
3. Click OK twice to return to design view.
4. Preview your chart as HTML or using the interactive report viewer. Click any column to verify it points to the Ask.com search for that country.

Working with Bucket Properties and Hidden Measures

To create a hyperlink with more complexity, use advanced configuration.

Open advanced configuration for your chart:

1. From design view, double-click the chart to open the HTML5 Chart Edit dialog.
2. Click Switch to advanced configuration.

Before creating a new hyperlink, you can view the hyperlink you just created to see how it is configured in advanced view.

View the existing hyperlink:

1. Select Category Levels > Level 1 and click Modify.

The Category Levels dialog for this category is displayed. This dialog shows details for the category, such as name and value type.

2. If you want, take the opportunity to name the category. For this example, you can name it Country.
3. Click Bucket Properties to see the hyperlink bucket properties for the existing hyperlink.
4. Click OK to return to the HTML5 Chart Edit dialog

Defining Bucket Properties for HTML5 Chart Hyperlinking

Add a series for Year:

To make this example a little bit more useful, and to see how you can use hyperlink information from different dimensions, this example shows how to add an extra dimension called Year, so the chart can display the number of orders placed in a specific country in a specific year. Then you can create a hyperlink that contains both the country and the year.

1. Double-click the chart.
2. Click the Chart Data tab and select the Configuration sub-tab.
3. Click Add in the Series Levels area.
4. Add a new series level configured as shown below:
     Name: Year
     Expression: YEAR( $F{ORDERDATE} )

Adding a Series Level to Define Buckets

5. Click OK twice.

Once again, you can preview the chart. Now, for each country, the chart shows the number of orders split by year.

Column Chart with Order Numbers Split by Year

Create a measure to hold the series hyperlink:

To create a more complex hyperlink, you can use a measure. Measures are usually designed to hold numeric values, most of the time the result of some aggregation function (in our example we show the count of orders). But a measure can actually be anything.

The following example creates a URL string:

Name: URL Measure
Hidden:  true (It is very important to check the checkbox, because you are not going to display this measure, it would not make sense as it's not numeric.)
Calculation: Nothing
Value Expression: "http://google.com/#q=" + $F{SHIPCOUNTRY} + " " + YEAR($F{ORDERDATE})
Value Class Name: java.lang.String

Defining the URL to Open when the Measure is Clicked

For this example, the most important things to note are:

     The measure is marked as Hidden.
     The calculation type is set to Nothing.
     The class of the measure is String. Specifically the example creates a String URL with a reference to both the country and the year of the order.

Create a hyperlink that uses a hidden measure:

6. Click OK to return to the HTML5 Chart Edit dialog box.
7. Select Measure 1, the visible measure used for the columns in the chart.
8. Click Modify.
9. If you want, change the name of Measure 1 to Number of Orders.
10. Click Edit Hyperlink.

Creating a Hyperlink for the Measure

11. Set the following values:
     Use Hyperlink: true
     Hyperlink Target: Top
     Hyperlink Type: Reference
     Use Measure Value: Select this and enter the name of the measure that contains the expression for the hyperlink, URL Measure.
12. Click OK three times to return to design view. Then save the report and preview it as HTML.

Now, each column in the stacked column chart points to a search for the corresponding country and year.

Version: 
Feedback
randomness