ActiveReports for .NET 3 Online Help Request technical support
Parameters with Charts
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Parameters Walkthroughs > Parameters with Charts

Glossary Item Box

Parameters can be used with charts to connect the information shown in the chart to that shown in the report. By setting a parameter for the field that links the report to the chart, the report can pass the information to the chart through the parameters.

This walkthrough illustrates how to set up a chart using parameters to link the report to the chart.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

When you have finished this walkthrough, you will have a report that looks similar to the following.

Creating a new Visual Studio project

To create a new Visual Studio project

  1. Open Visual Studio.
  2. From the File menu, select New > Project.

  3. Select the project type and click on Windows Application.
  4. Change the name of your project and click OK.

Adding an ActiveReport to a Visual Studio project

To add an ActiveReport to a Visual Studio project

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 3.0 File and rename the file rptChartParams.
  4. Click Open.

Connecting the report to a data source

To connect the report to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Select the "OLE DB" tab.
  3. Click on Build.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the NorthWind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "SELECT * FROM Products ORDER BY CategoryID, ProductName".
  8. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to the reports

  1. Right-click on the report and delete the PageHeader/Footer section pair.
  2. Right-click on the report and insert a GroupHeader/Footer section pair.
  3. Make the following changes to the GroupHeader section:
    • Change the Name property to ghCategoryID
    • Change the DataField property to CategoryID
    • Change the GroupKeepTogether property to All
    • Change the Height property to 5.65 in
  4. Change the Height property of the Detail section to 0.23 in.
  5. Change the Height property of the GroupFooter section to 0 in.
  6. Add the following controls to rptChartParams, setting the properties as indicated:

     

    Control DataField Name Text Section Location
    Label lblCategoryID Category ID Number: ghCategoryID 1.78, 0
    TextBox CategoryID txtCategoryID CategoryID ghCategoryID 3.72, 0
    ChartControl chartControl1 ghCategoryID 0.063, 0.313
    Label lblProductName Product Name ghCategoryID 0.23, 5.43
    Label lblUnitsInStock Units In Stock ghCategoryID 5, 5.43
    TextBox ProductName txtProductName ProductName Detail 0.23, 0
    TextBox UnitsInStock txtUnitsInStock UnitsInStock Detail 5, 0.23

     

Setting a data source for the chart

To connect the data source to a database

  1. With the chart control highlighted, click the Data Source verb below the Properties Window to open the Chart DataSource dialog.
  2. Click Build.
  3. Select "Microsoft Jet 4.0 OLE DB Provider" and click Next.
  4. Click the ellipsis button to browse to the NorthWind database. Click Open once you have selected the file.
  5. Click OK to continue.
  6. In theQuery field, type "SELECT * FROM Products WHERE CategoryID = <%CategoryID||1%> ORDER BY ProductName."
  7. Click OK to return to the report design surface.
 When using parameters, the chart draws at run time but not at design time if you do not provide a default value.
If you don't set the ORDER in both SQL statements (i.e. that of the report and that of the chart), the chart data will not be ordered.

Setting the chart's properties

To set the chart's properties

  1. With the chart control highlighted, click the ChartAreas (Collection) property in the Properties Window, then click the ellipsis button to open the ChartArea Collection Editor.
  2. In the defaultArea Properties, click the Axes (Collection) property, then click the ellipsis button to open the AxisBase Collection Editor.
  3. Click the AxisX member, and set its LabelFont > Angle property to 90 so the ProductName labels will not overlap.
  4. Click the AxisY member, and set its Title property to "Units in Stock".
  5. Still in the AxisY member, expand the MajorTick property treeview node and set the following properties:
    • Change the GridLine > Style property to Dot
    • Change the GridLine > Color property to Silver
    • Change the GridLine > Weight property to 1
  6. Click OK to return to the ChartArea Collection Editor.
  7. Click OK to return to the report design surface.
  8. With the chart control highlighted, click the Series (Collection) property in the Properties Window, then click the ellipsis button to open the Series Collection Editor.
  9. Click Series1 to select it.
  10. Change the ValueMembersY property to UnitsInStock.
  11. Change the ValueMembersX property to ProductName.
  12. Remove Series2 and Series3.
  13. Click OK to return to the report design surface.
  14. With the chart control highlighted, click the Titles (Collection) property in the Properties Window, then click the ellipsis button to open the Title Collection Editor.
  15. In the header properties, change the Text property to "Products In Stock."
  16. Remove the footer title and click OK to return to the report design surface.
  17. With the chart control highlighted, click the Legends (Collection) property in the Properties Window, then click the ellipsis button to open the Legend Collection Editor.
  18. Change the Visible property of the defaultLegend to False.
  19. Click OK to return to the report design surface.

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer.

See Also

©2009. All Rights Reserved.