Working with Charts

Crystal Reports .NET utilizes a sophisticated graphing engine based on technology from ThreeD Graphics and can create just about any type of chart or graph you can imagine.

Throughout this chapter, you have been working on the international sales report. There are groups for the Country, Region, and City fields in the report, and with all of the summary fields and other content, the report runs over multiple pages, making it difficult to visualize the information contained within. In the following pages, we are going to add a chart to the first page of the report we have been working with, which will provide the user with an overview of the information displayed.

To begin, open the report we originally created (and that you copied earlier) in the Report Designer by double-clicking the report in the Solution Explorer.

To add a chart to this report, right-click the report and select Insert ^ Chart, which will open the Chart Expert dialog, shown in Figure 3-31.

Figure 3-31

You may have noticed when working with the Standard Expert that there was a tab for Charts; the same Chart Expert is used in both places.

There are a number of different templates, including bar charts, pie charts, and 3-D charts, many of which won't be covered in too much detail here. A sample icon of how each will look has been included for you in the Chart Type to the left of the Chart Expert. Please keep in mind that each one of these graph types requires a specific set of information. For example, a pie chart may need only two values passed to it (for the names of the pie slices and their values), whereas a three-dimensional chart may require three or more values.

When you select a graph type that does not match the data you have available and attempt to exit the report expert, a dialog will appear with three options:

□ Continue with Selected Data and Chart Type

□ Change Data or Chart Type Selection (Return to Chart Expert)

□ Let the Expert Choose the Most Appropriate Chart for Data Selected

If you select the first option and choose to ignore the warning message, your chart will be unpredictable at best. The charting engine will attempt to work with the values you have presented, but it may present a blank graph or one in which the values are just plain wrong. It is better to use the second or third option to ensure that your graph format matches the data available in your report.

In any case, we know that our report has multiple groupings and summary fields, so we should be fine if we select the Pie Chart with the 3D effect by clicking the icon for this graph, shown in Figure 3-32.

Figure 3-32

Next, select the type of graph you want to create using the Data tab of the Chart Expert, as shown in Figure 3-33.

This dialog says there are four different types to choose from (Advanced, Group, Cross-Tab, and OLAP), but OLAP graphs rely on an underlying OLAP grid inserted onto your report. That feature is not supported in Crystal Reports .NET (at the time of writing, it is supported in the full retail versions of Crystal Reports), so this option will remain permanently grayed out. The Cross-Tab button will also be grayed out if you haven't inserted a Cross-Tab into your report.

Figure 3-33

Here are the graph types available for use:

□ Advanced Graphs—Advanced graphs require two fields: an On change of field and a Show values field. These are similar to the X and Y fields you would normally use if you were plotting a graph by hand. Just like a manual graph, you can have multiple On change of and Show values fields. You can also determine the order for the On change of field and apply TopN/BottomN/Sort

All to the same. For the Show field, you can set the summary operator—sum or average, for example—or choose not to summarize the values at all.

□ Group Graphs — These are based on at least one group and one summary field that appear in your report. Group graphs can be placed at the Report Header/Footer level or on the Group Header/Footer level, where they will show the data only for that particular group.

□ Cross-Tab Graphs—These rely on an underlying Cross-Tab grid to provide the required data. These types of graphs can also appear on the Report Header/Footer level or on the Group Header/Footer level with the same filtering of data specifically for that group.

In this case, we have a group and a summary field inserted into our report, so you can select to place the chart once per report, specifying On Change Of Customer.Customer Name, and showing Sum of Orders.Order Amount.

Once you have selected the graph and data type for your report, the only thing left in the Chart Expert is to set the text that will appear on your chart or graph, so select the Text tab. By default, Crystal Reports .NET will automatically enter some text for you, or you can override the text and its formatting if you choose. To enter your own text, uncheck the box beside any of the titles and enter your own title in the textbox provided.

When you click OK to exit the Chart Expert, your Chart will be added to your Report Header. When you see the report in the designer, a pie chart should now be displayed in the Report Header. This isn't an accurate drawing of your graph. In fact it is nothing like your graph; it is just a placeholder to show where in the report the graph will be positioned. If you preview the graph in a Windows form, it will look something like Figure 3-34.

Another option to increase readability would be to make the chart larger. The chart object inserted into your report is just like any other object in that it can be resized to fit your needs; you could even resize the graph to take up the entire first page if that suits the needs of the report.

If you have a graph or chart inserted into your report, you can control the content by right-clicking directly on top of the chart and selecting an option from the menu. The Chart Expert can be used to alter the graph in the way that we have described so far in this section. You may have noticed that the Chart Expert includes an option on the first tab labeled "Automatically set chart options." If you uncheck this box, two more tabs will appear, allowing you to control other aspects of the report, including the formatting for the graph axes and the general settings (like color, marker size, and so on).

Under Format Chart are the Template, General, and Titles options, which also allow you to customize the appearance of your chart. The options in all of these menus are context sensitive; for example, you can perform different types of formatting to a pie chart than you can to a bar chart. These options are all relatively simple, so we'll leave it to you to explore the almost endless possibilities.

Unfortunately, if you have used the retail version of Crystal Reports before, you will probably be wondering what happened to the Chart Analyzer, which allows you to open the graph in another tabbed window. Crystal Reports .NET does not include the full capabilities of the Chart Analyzer, so if you really need to use some of the advanced formatting features for charts and graphs, you are going to have to buy a retail copy of Crystal Reports.

Was this article helpful?

0 0

Post a comment