Bar charts are useful in comparing items across categories. This walkthrough illustrates how to create a simple bar chart using the ActiveReports chart control.
The walkthrough is split up into the following activities:
- Adding a chart control to the report
- Setting a data source for the chart
- Setting the chart's properties
|
Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough. |
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).
When you have finished this walkthrough, you will have a report that looks similar to the following.
To add a chart control to the report
- Resize the section in which you want to place the chart.
- Click the ChartControl in the ActiveReports toolbox and draw it onto the report.
- If the chart wizard appears, click Cancel.
|
Tip: If you do not want the chart wizard to appear each time you add a chart, clear the Auto Run Wizard checkbox. You can still access the wizard via the command verbs (see below). |
- Select the ChartControl and set its Size property to 7.5, 3.5 in.
To set a data source for the chart
- With the chart control highlighted, click the Data Source verb below the Properties Window.
|
Tip: If the verb is not visible, right-click an empty space in the Properties Window and select Commands to display verbs. |
- In the Chart DataSource dialog box that appears, click the Build button.
- In the Data Link Properties window, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
- Click the ellipsis button (...) to browse to the Northwind database. Click Open once you have selected the file.
- Click the OK button to close the window and fill in the Connection String.
- In the Query field, enter the following SQL query
SQL Query |
Copy Code |
SELECT ShipCountry, SUM(Freight) AS FreightSum FROM Orders GROUP BY ShipCountry |
- Click OK to save the data source and return to the report design surface.
To set the chart's properties
- With the chart control highlighted, click the Customize verb below the Properties Window to open the Chart Designer window.
- In the ChartAreas view which displays by default, click the Axes bar to expand it.
- Click Axis X, and on the Common tab in the pane to the right, type Country in the Title textbox and increase the font size to 12.
- Choose the Labels tab in the Axis Properties pane on the right, select the Staggered Labels option to avoid overlapping labels and set the Text angle property to 45.
- Click Axis Y on the left, and on the Common tab in the pane to the right, type Freight in the Title textbox and increase the font size to 12.
- Click the Titles bar on the left to expand it and display Title Properties in the pane to the right. In the list of titles, header is selected by default.
- Type Simple Bar Chart in the Caption textbox, and increase the font size to 14.
- Select the footer in the list of titles to the left, and delete it.
- Click the Series bar on the left to expand it and display Series Properties in the pane to the right. Series1 is selected by default.
- In the Data Binding box, set X (Name) to ShipCountry, and set Y to FreightSum.
- Delete Series2 and Series3.
- Click the Legend bar on the left to expand it and display Legend Properties in the pane to the right. defaultLegend is selected by default.
- Clear the Visible checkbox at the top of the Common tab to hide the legend.
- Click the Finish button to exit the Chart Designer.
See Also