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. Use 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. | Place the fields in the Detail band by dragging them from the Outline. This creates a small table of the values to display in the chart. |
Initial Report Design |
 |
| 4. | Expand the Summary band to 378 pixels. |
Summary Band Properties |
 |
| 5. | From the Palette, select the Chart tool and drag it into the Summary band. When you add a new chart element to a report, Jaspersoft Studio shows the Chart Wizard from which you can pick the chart type. |
 |
Chart Wizard |
| 6. | Select the Pie 3D Chart icon and click Next. |
| 7. | Accept the default configuration and click Finish. |
| 8. | Expand the chart to fill the Summary band. |
 |
Chart in Summary Band |
 | In Design view, the chart shown is a placeholder that doesn't display your data. |
To configure a chart:
| 1. | Double click on the chart element. The Chart Wizard > Chart Data Configuration window opens. |
Chart Wizard > Chart Data Configuration |
 |
In this window you select data to use in your chart.
Depending on the dataset type that you have selected, the window’s Chart Data tab shows the fields within the specified dataset. Detailed descriptions of the various field types and their functionality are available in the JasperReports Library Ultimate Guide.
| 2. | The Max slices to show field is useful for charts with many slices. When set, your chart only shows the number of slices you specify; additional values are included in a slice labeled Other. |
Set this field to 10.
| 3. | On the Dataset tab, you can define the dataset within the context of the report. |
The Reset on drop-downs allow you to periodically reset the dataset. This is useful, for example, when summarizing data relative to a special grouping. Increment on specifies the events that determine when new values must be added to the dataset. By default, each record of the dataset used to fill the chart corresponds to a value printed in the chart. This behavior can be changed, forcing the engine to collect the data for the chart at a specific time (for instance, every time the end of a group is reached).
Dataset Tab |
 |
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.
| 4. | 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 must be a unique value to identify a slice of the pie chart. If a key value is repeated, the label and value values previously associated with that key are overwritten. A key can never be null. |
| • | Value expression specifies the numeric value associated with the key. |
| • | Label expression allows you to specify a label for each slice of the pie chart. This expression is optional, and the default value is the key value. |
Next to each field, click the
button. Enter the following:
Value: $F{orders}
Label: $F{shipcountry}
Key: $F{shipcountry}
| 6. | Save your report, and preview it to see the result: |
 |
Final Chart |
In this chart, each slice represents a country, and the value of the slice represents the shipping total for that country.
Recommended Comments
There are no comments to display.