ActiveReports for .NET 3.0 allows you to drop a third party control as a custom control onto an ActiveReport.
This walkthrough illustrates how to use ChartFX as a custom control with ActiveReports.
This walkthrough is split up into the following activities:
- Adding an ActiveReport to a Visual Studio project
- Adding the ChartFX control to the ActiveReport
- Adding a label to the page header
- Adding code for the chart control
To complete the walkthrough, you must have ChartFX installed.
When you have completed this walkthrough, you will have a report with a chart that looks similar to the following.
Adding an ActiveReport to a Visual Studio project
To add an ActiveReport to your project
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptChart.
- Click Open.
Adding the ChartFX control to rptChart
To add the ChartFX control to rptChart
- Click on the ChartFX control in the appropriate toolbox to select it.
- To add the ChartFX chart control to Visual Studio 2003, right-click the toolbox and select Add/Remove items.
- Select Chart (SoftwareFX.ChartFX namespace, ChartFX(6.2.x)).
- Click the OK button.
- Drop the Chart control onto the Detail section of rptChart.
- Resize the chart control to fill the Detail section.
Adding a Label to the PageHeader
To add a label to the PageHeader
- Drag and drop the Label control from the ActiveReports toolbox to the PageHeader section.
- Change the Alignment property to Center.
- Change the Font Size property to 14 pt.
- Change the Text property to "ChartFX Chart based on random values with ActiveReports for .NET 3.0".
- Resize the Label to show the text on two lines.
Adding code for the ChartFx control
Before you can use the following code, you need to add references to ChartFX for .NET (Windows.Forms) and ChartFX Base to your project.
To write the code in Visual Basic or C#
- Double-click the Detail section for rptChart. This creates an event-handling method for the Detail_Format event.
-
The following example shows what the code for the method looks like.
' Visual Basic
Private Sub Detail1_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail1.Format Dim r As New System.Random() Dim ChartControl1 As SoftwareFX.ChartFX.Chart 'Cast customControl as ChartFX chart ChartControl1 = CType(Me.CustomControl1.Control, SoftwareFX.ChartFX.Chart) Dim i As Integer Dim j As Integer 'Open the communication channel ChartControl1.OpenData(SoftwareFX.ChartFX.COD.Values, 3, 3) For i = 0 To 2 For j = 0 To 2 'Assign the values to the series selected ChartControl1.Value(i, j) = r.NextDouble() * 100 Next j Next i 'Close the communication channel ChartControl1.CloseData(SoftwareFX.ChartFX.COD.Values) End Sub//C#
private void detail_Format(object sender, System.EventArgs eArgs) { System.Random r = new System.Random(); Chart ChartControl1 = new Chart(); //Cast customControl as ChartFX chart ChartControl1 = ((SoftwareFX.ChartFX.Chart)this.customControl1.Control); //Open the communication channel ChartControl1.OpenData(SoftwareFX.ChartFX.COD.Values, 3, 3); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { //Assign the values to the series selected ChartControl1.Value[i, j] = r.NextDouble() * 100; } } //Close the communication channel ChartControl1.CloseData(SoftwareFX.ChartFX.COD.Values); }
Viewing the report
To view the report
- Add the ActiveReports viewer control to a Windows Form.
- 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. |