Before you add a chart, consider the best way to display your data. Available chart types are listed in “HTML5 Chart Types”.
Creating an HTML5 chart
select * from orders
| 3. | Choose HTML5 Charts from the Components Pro section of the Palette, and drag it into your report. |
![palette.png.8a0fd9bc70d1cbc256e5d05cc3bdeb1e.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
Palette |
| 4. | Select a chart type based on the information you want to display. See“HTML5 Chart Types” for help. |
For this example, we'll choose Pie chart.
![html5-chart-types.png.dc2a13d65cc075359e4a39e4a1df67a3.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
Chart Types |
Your report now includes a sample chart. The Design tab doesn't display live data. After you configure your data for use with an HTML5 chart, you can click Preview to see the chart with your data.
Pie Chart Example |
![pie-chart-example.png.4559bcf06b3eb350d3eb29cbf09ccb07.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
| 5. | Right-click the chart, and choose Edit Chart Properties. The Chart Properties dialog includes tabs for configuring chart properties, chart data, and hyperlinks. |
HTML5 Charts Properties > Chart Data > Configuration |
![html5-chart-config.png.8b683ce233fdfcefda973479b6f8f4dd.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
| 6. | Go to the Chart Data tab and click the Configuration tab. |
| 7. | Highlight Level1, and click Modify. |
| 8. | Name the Expression Country. |
| 9. | Click ![jss-icon-expression-editor.png.30e60e810992a5f2dac99f23567a2bf3.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
| 10. | In the Values field, create a measure called Total Orders. |
| • | The Label Expression should be “Total Orders”. |
| • | The Calculation type is DistinctCount. |
| • | In the Value Expression field, add the orderid field. |
| • | The Value Class Name should be java.lang.Integer. |
| 11. | Click OK to close the Chart Properties dialog. |
| 12. | Save, then click the Preview tab to see your chart. To preview your chart in a web browser, choose XHTML Preview from the Preview drop-down. HTML5 charts require XHTML for web preview. |
Your HTML chart preview is interactive. Hover over a pie segment to see the exact number of orders.
Editing HTML5 Charts
Continue using the HTML5 pie chart from the previous example to complete the following tasks.
To edit the title of an HTML5 chart:
| 1. | Right-click the chart and select Edit Chart properties. |
| 2. | Click the Chart Properties tab. |
| 3. | Click Title and enter Orders by Country in the text box. You can also customize alignment, color, and font. |
To filter the data in the chart:
| 1. | Click the Chart Data tab, then click its Dataset tab. |
| 2. | By the Increment expression text box, click ![jss-icon-expression-editor.png.ff61616700560ad45bcf129d058700ef.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
| 3. | Filter your data set by adding an Increment expression such as: |
$F{SHIPCOUNTRY}.startsWith("A") ||
$F{SHIPCOUNTRY}.startsWith ("U") ||
$F{SHIPCOUNTRY}.startsWith ("I") ||
$F{SHIPCOUNTRY}.startsWith ("S")
| 5. | Save and click Preview again to view the edited chart. |
Filtered Pie Chart |
![filtered-pie-chart.png.ec0a6c082705ac7c4df31823c7589b00.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
To change chart type:
Before beginning this task, make sure your data is appropriate for the new chart type.
| 1. | Right-click your chart and choose Edit Chart properties. |
| 2. | In the lower-left section of the dialog box, click the Change Chart Type button to open the HTML5 Chart type selection window. This window provides some guidance about which dataset type is used by each type of chart. |
| 3. | For this example, choose Bar and click OK. |
Jaspersoft Studio discards data that's not right for the new chart type.
| 5. | Save and preview your report. Because it was originally designed as a pie chart, there's no label for the Y-values. |
To add an additional measure to a bar chart:
Editing works similarly for all charts, depending on the type of data presented.
| 1. | On the Design tab, right-click your chart and choose Edit Chart properties. |
| 2. | Click the Chart Data tab, then click its Configuration tab. Because this is now a bar chart, there are sections to define Series Levels and additional measures. |
| 3. | In the Measures section, click Add. Enter the following information: |
| • | Label Expression: “Average Freight” |
| • | Value Expression: $F{FREIGHT} |
| • | Value Class Name: java.lang.Integer |
Click OK and Close.
| 4. | Save and Preview the chart. HTML charts are interactive. |
To add a series to a bar chart:
| 1. | On the Design tab, right-click your chart and choose Edit Chart properties. |
| 2. | Click the Chart Data tab, then click its Configuration tab. |
| 3. | In the Series Levels section, click Add. Enter the following information: |
| • | Expression: new java.text.SimpleDateFormat(“yyyy”).format( $F{ORDERDATE} ) |
| • | Value Class Name: java.lang.Comparable |
Click OK and Close.
| 4. | Save and Preview your report. You see two measures per year, Total Orders and Average Freight, grouped by Country. |
Bar Chart with Second Measure and Series |
![initial-bar-chart.png.83e1666061f94b1a147d5436aa485942.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
Creating Hyperlinks
With HTML5 charts (Highcharts) functionality added to JasperReports, using hyperlinks in charts is similar to using JFreeCharts (regular Charts) and Fusion charts (Charts Pro). You open the chart properties, select the Hyperlink tab, and add your link.
![note-icon-ns.png.1aef2726cd0e406f2dad4fc18b96c01b.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) | Because HTML5 charts are so different from other chart types supported by Jaspersoft Studio, their chart items (bars or pie section) support hyperlinks differently than other types of chart. This section gives some basic steps for defining hyperlinks for HTML5 charts. For more detailed instructions, see Creating Hyperlinks in HTML5 Charts. |
| 1. | Right-click your bar chart and select Edit Chart properties. |
| 2. | Click the Chart Data tab, then click its Configuration tab. |
| 3. | In the Categories Levels section, double-click Country. |
| 4. | Click the Bucket Properties tab, and click Add. |
| 5. | In the Property name text entry box, enter url. |
| 6. | Click ![jss-icon-expression-editor.png.f9feb8663fac375583a8ae4177afb902.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) |
"http://www.ask.com/web?q=" + $F{SHIPCOUNTRY}
To add the hyperlink:
| 1. | Back in the Chart Data tab, click its Configuration tab. |
| 2. | Double-click the measure Total Orders. |
| 3. | Click the Advanced Properties tab, then click the Hyperlink button. That provides a shortcut to the two most important properties needed to create a hyperlink. |
| 4. | Double-click hyperlinkReference (SeriesItemHyperlink). The Edit property dialog opens with some information filled in. You customize this information to the values you need. |
| 5. | Click the radio button for Use a bucket property value and enter Country.url. |
| 7. | Save and preview your report. In the HTML preview, click the bar for any country to open the Ask.com page for that country. |
To create hyperlinks that use expressions:
![note-icon-ns.png.9b0f9f4de3c23c2bd2e0ae8f30d3ecc1.png](https://community.jaspersoft.com/applications/core/interface/js/spacer.png) | Bucket-level properties are the only place where you can create expressions to be used with your link. If you're 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. For example, if you are using a pie chart, the category bucket may have a property called myUrl which contains your URL built with the category value. |
This can be done in Edit Chart Properties > Chart Data > Configuration.
| 3. | In the Categories Levels section, click Add. |
| 4. | Click the Bucket Properties tab, and click Add. |
| 5. | Create the myUrl property, then click OK. |
| 6. | Next, Identify the measure to which you need to add a link. |
This can be done in Edit Chart Properties > Chart Data > Configuration.
| 7. | In the Measures section, click select the measure you want to link to, and click Modify. |
| 8. | In the advanced properties of your measure click Hyperlink. |
This creates a couple of properties. Edit them by assigning the proper value (again, you need 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 rename one of the measure's advanced properties (see step 4 in the previous procedure) to _report and enter the corresponding value, and if you need to pass parameter values you also need to add them as measure properties.
Recommended Comments
There are no comments to display.