After you have selected your chart type and the data that you
would like to include in the chart, you have the ability to modify the axis
settings. On charts where data is listed on the different axes, having the
ability to set minimum/maximum values, format of the number and how the data is
divided in the axes can help the look of how the data is rendered to be more simplistic.
Figure 4: The Chart Expert Axes Tab
The Charting Expert contains features that allow you to
modify and format the chart legend and any text on the chart, such as the
title, subtitle or footer. Options that are more specific to the chart type
will also appear under the options tab. Figure 5 is an example of the options
screen for a pie chart. You will notice options in the "Customize settings"
region that allows you to set the size of the pie and also detach pie slices.
Figure 5: Chart options specific to the chart type
The Charting Expert is not the only place to create settings
for a chart. If you right click on the chart and select "Chart Options,"
you will be presented with a dialog that allows you to set more options that
are specific to the type of chart that is being rendered. Notice in Figure 6
that you are able to "Explode" the pie chart. This feature allows the
pieces of the pie chart to be separated.
Figure 6: Chart Options Dialog
Chart Templates
Newer versions of Crystal Reports support the ability to use
Chart Templates. Chart Templates are similar to the Report Templates feature
included in Crystal Reports XI and 2008. Crystal Reports provides a set of built-in
templates that you can use to format your report. The built in templates
include options to solve many formatting issues. Situations, such as rendering data
with grey scale colors, rendering data in larger fonts to adhere to
accessibility standards, and also a template to organize a chart that has a
large dataset, are included. The advantage of chart templates in Crystal
Reports is that you can use a user defined template. User defined templates are
great if you have worked hard to format a chart to meet style requirements or
need to adhere to a corporate standard. After you create styling for the first
chart, you can save the template (templates are saved as 3tf Chart Template
Files) and then use the template to format other charts. Style components such
as font, font size and colors are inherited from the selected template.
Figure 7: Selecting a chart template
Chart Expert Color Highlighting
The Charting Expert allows you to select which color will be
used for the data that it represents. The "Color Highlight" tab found
on the Chart Expert allows you to select a data point and set the exact color that
you would like this data point represented in.
Figure 8: Setting the color of specific data
Beyond the Default Crystal Reports Charts
Crystal Reports 2008 is a robust tool that satisfies the
reporting needs of many businesses. However, some companies may find the
charting features included in Crystal Reports 2008 incomplete and may be
looking for additional features. For years in the developer community there has
been an outcry for better charting functionality. Crystal Reports 2008 has
responded and extends upon the existing Crystal Reports functionality, but there
are still gaps for some companies. Sometimes having the ability to add shadows
or having the ability to add more intense image features to charts helps give a
report the style that it needs.
There are many third party controls that will allow you to
pass a set of data to the control, set a few options and the control will
render a chart. Controls, such as .net Charting and Dundas, provide a very
powerful API to create charts that are both complex and stylish. Most of these
third party charting controls have the ability to save the chart as an image
such as PDF, PNG or JPG. Since Crystal Reports XI, the Dynamic Image feature
has allowed us to set the path of an image dynamically, and therefore, allows
us to include charting images from 3rd party controls.
The chart in Figure 9 is a pie chart that was created in
Crystal Reports 2008. Someone who is familiar with the business domain that
this report was created for would be able to look at this chart and have a good
idea of where their customers are located. This chart contains all data that is
needed for someone to get the job done, and also looks aesthetically pleasing.
Figure 9: Pie chart created with Crystal Reports
2008
The chart in Figure 10 represents the exact same dataset,
but has more pizzazz. The chart in Figure 10 was created using a 3rd party
control for .NET called .NET Charting.
Figure 10: Pie chart created with 3rd party control
.net Charting
It is not in the scope of this article to cover exactly how
each of the third party charting controls creates the chart, it is merely
important to be aware of this pattern. Figure 11 creates a chart image (a PNG
file) from a set of data and then saves the chart as a PNG to the disk.
Figure 11: Code to create a pie chart with .NET
Charting
public string GetChartPath(ref Chart chart)
{
string tmpRtn = string.Empty;
// set the title, legend box and label options
chart.Title = "Customer Regions";
chart.TitleBox.Padding = 10;
chart.TitleBox.Background.Color = Color.LightBlue;
chart.TitleBox.Background.GlassEffect = true;
chart.TitleBox.Background.Bevel = true;
chart.LegendBox.Background.Color = Color.LightBlue;
chart.LegendBox.Background.GlassEffect = true;
chart.LegendBox.Background.Bevel = true;
chart.XAxis.Label.Text = "Regions";
chart.YAxis.Label.Text = "Count of Customers";
chart.Width = 800;
chart.Height = 600;
// set the chart type options
chart.Use3D = true;
chart.Type = ChartType.Pie;
chart.ChartArea.Background.Bevel = true;
chart.ShadingEffectMode = ShadingEffectMode.Three;
chart.DefaultSeries.DefaultElement.Transparency = 20;
chart.DefaultSeries.DefaultElement.ExplodePieSlice = true;
chart.DefaultSeries.DefaultElement.ShowValue = true;
chart.DefaultSeries.DefaultElement.ShowValue = true;
// set the charting data
chart.SeriesCollection.Add(GetChartData());
return chart.FileManager.SaveImage();
}
After you have rendered the chart image, you need to get the
path where the image was saved to the report. The easiest way to do this is
just pass the chart image path with the set of data you are using to render
your report. When the chart image path is included in the dataset, you can easily
grab the path to set the dynamic image.
Figure 12: Code to add the chart path to a dataset
DataSet chartData = new DataSet();
DataTable chartTable = new DataTable();
chartTable.Columns.Add("ChartImagePath");
// build the chart and set the image path to the ChartImagePath field
chartTable.Rows.Add(new object[] {
GetChartPath(ref chartCustomers) });
chartData.Tables.Add(chartTable);
chartData.AcceptChanges();
Adding a dynamic image to your report
Follow the steps given below to add a dynamic image to your
report.
·
Add an image to your report.
·
Right click on the image and selecte "Format Graphic."
·
On the "Picture Tab," Click the formula button (X+2
button).
·
Create a formula to pull the chart image path from the dataset.
Figure 13: Graphic location
Figure 14: Graphic location formula