This section shows you how to use the Chart tool to build a report containing a Pie 3D chart and explore chart configuration.
To add a chart to a report:
| 1. | Create a new report using the Sugar CRM data source. |
| 2. | Use this query to display the count of orders in different countries: |
select COUNT(*) as orders, shipcountry from orders group by shipcountry
| 3. | Drag the fields from the Outline to the Detail band to create a small table of values to display in the chart. |
|
Initial Report Design |
| 4. | Expand the Summary band to 378 pixels. |
|
Summary Band Properties |
| 5. | Drag the Chart tool from the Palette into the Summary band. The Chart Wizard opens. |
|
Chart Wizard |
| 6. | Select the Pie 3D Chart and click Next. |
| 7. | Accept the default configuration and click Finish. |
| 8. | Expand the chart to fit the Summary band. |
|
Chart in Summary Band |
| In the Design tab, the chart is a placeholder and doesn't display your data. |
To configure a chart:
| 1. | Double click the chart. The Chart Data Configuration window opens. |
|
Chart Wizard - Chart Data Configuration |
| 2. | Select data to use in your chart. |
| The Chart Data tab shows the fields within the specified dataset. You'll find detailed descriptions of field types and their functionality in the JasperReports Library Ultimate Guide. |
| 3. | Set 10 for Max slices to show. For a chart of many slices, this field specifies the number to show. A chart slice labeled Other contains the slices not shown.
|
| 4. | On the Dataset tab, you can define the dataset within the context of the report. |
You can use the Reset on controls to periodically reset the dataset. This is useful, for example, when summarizing data relative to a special grouping. Use the Increment on control to specify the events that trigger addition of new values to the dataset. By default, each record of the chart's dataset corresponds to a value printed in the chart. You can change this behavior and force the engine to collect data at a specific time (for instance, every time the end of a group is reached).
Set Reset on to Report since you don’t want the data to be reset, and leave Increment Type set to None so that each record is appended to your dataset.
|
Dataset Tab |
| 5. | Also in the Chart Data Configuration dialog, enter an expression to associate with each value in the data source. For a Pie 3D chart, three expressions can be entered: key, value, and label. |
| • | Key expression identifies a slice of the chart. Each key expression must be a unique. Any repeated key simply overwrites the duplicate key. A key can never be null. |
| • | Value expression specifies the numeric value of the key. |
| • | Label expression specifies the label of a pie chart slice. This is the key expression by default. |
Next to each field, click the button. Enter the following:
Value: $F{orders}
Label: $F{shipcountry}
Key: $F{shipcountry}
| 7. | Save your report, and preview it to see the result. |
|
Final Chart |
In this chart, each slice represents a country and the shipping total for that country.
Recommended Comments
There are no comments to display.