This document provides you with step-by-step instructions on how to create a report with a Chartcontrol bound to data, so that a particular series has its own data source, and other settings.
This example describes how to construct a chart of products and their prices for a chosen category using the data from the Northwind database (the sample nwind.mdbdatabase). Note that in this example, the series' data have a single data source to simplify the project. But since the series can be bound to data independently, different data sources can be used for different series, if necessary.
To create a chart, follow the steps below.
- Create a new report.
-
Drop the Chartcontrol from the Toolboxonto the report's Detail band.
Note Note that in this instance, the Chart Wizard may be invoked (if its "Show wizard every time a new chart is added" option is enabled). In this example, we don't need to use the wizard, so click Cancelto close the wizard's window and manually customize the chart.
-
To bind the chart to a data source, click its Smart Tag, and in the invoked actions list, expand the Data Sourcedrop-down selector and click Add New DataSource. The Report Wizard dialog will appear.
The wizard will guide you through the process of assigning a data source to the chart. For detailed instructions on the wizard's steps, refer to Bind a Report to Data, as this process is similar.
-
Now, the created dataset is assigned to the chart's Data Sourceproperty. Also, set its Data Memberproperty, to define from which table or view of your dataset the chart should obtain data. Then, the chart's Data Adapterproperty will be automatically defined. This means that the chart is bound to the data.
Note Note that after these steps, the report's Data Sourceproperty must be set to None. Otherwise, the chart will be blank at the preview, and repeated as many times as there are records in the data source.
-
To add a series to the chart and specify its data binding properties, use the Series Collection Editor. It can be invoked either via the Property Grid, or via the Series...link in the chart's Smart Tag.
In the editor, create a series by clicking the Add...button and selecting the Barview.
Switch to the Propertiestab at the right of the editor's window.
Set the series' Data Sourceproperty to the created dataset, define the Argument Data Memberand Value Data Membersproperties.
Click Copy, to create another series with the same properties, and set its Viewproperty to Point.
To save the changes and quit the editor, click Close.
-
Note that after this step, there are too many data points, and the chart looks messy. The chart's Data Filtersproperty is intended to limit the number of data points shown by applying a filtering criterion. Select Series1in the chart by mouse click, then in the Property Grid locate the Data Filtersitem and click its ellipsis button, to invoke the Data Filter Collection Editor.
Click Addto add a criterion, and define its properties as shown in the following image.
To save the changes and quit the editor, click Close.
Repeat the same actions for Series2, i.e. choose its Data Filtersproperty, add a filter and define its Column Nameand Value.
-
To improve the chart's appearance, make the following corrections.
-
Remove the chart's legend, as it shows the same data for the series. To do this, select the legend item in the chart, and in the Property Grid, set its Visibleproperty to No.
-
The point labels for Series1 are unnecessary, so select the label and set its Visibleproperty to No.
-
Customize the Series2 marker's appearance. Replace the default circle with the upside-down triangle by the View.Point Marker Options.Kindproperty and set its Sizeto 12.
-
Rotate the X-axis labels for better readability. Select the AxisXitem in the chart by mouse click, and adjust properties for its labels (via the Labelproperty). For instance, if the Angleproperty is 20and the Antialiasingproperty is set to Yes, the labels look neat.
If required, it is possible to customize many other properties for the chart, which are not described here.
-
The chart is now ready. Switch to the Preview Tab, and view the result.