The Chart control allows you to bind charts to any type of data source, including arrays. You can create a chart without setting its data source and load the data into the control at run time. This walkthrough illustrates how to create a simple unbound chart.
The walkthrough is split up into the following activities:
When you complete this walkthrough you get a layout that looks similar to the following at run time.
To add an ActiveReport to the Visual Studio project
See Adding an ActiveReport to a Project for information on adding different report layouts.
To add the Chart control to the report
Property Name | Property Value |
---|---|
Location | 0, 0in |
Size | 6.5, 3.5in |
To configure the appearance of the Chart
Back on the design surface of the report, the chart appears empty except for the title.
To add the code to create a chart at run time chart in Visual Basic or C#
Double-click the gray area below the report. This creates an event-handling method for rptUnboundChart's ReportStart event. Add code to the handler to:
The following examples show what the code for the methods look like in Visual Basic.NET and C#.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
'create the series Dim series As New GrapeCity.ActiveReports.Chart.Series series.Type = Chart.ChartType.Bar3D 'connection string and data adapter Dim dbPath As String = "C:\Users\YourUserName\Documents\GrapeCity Samples\ActiveReports 11\Data\NWIND.MDB" Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dbPath" Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * from Orders WHERE OrderDate < #08/17/1994#", connString) 'create the dataset Dim ds As New DataSet da.Fill(ds, "Orders") 'set chart properties Me.ChartControl1.DataSource = ds Me.ChartControl1.Series.Add(series) Me.ChartControl1.Series(0).ValueMembersY = ds.Tables("Orders").Columns(7).ColumnName Me.ChartControl1.Series(0).ValueMemberX = ds.Tables("Orders").Columns(8).ColumnName 'angle the labels to avoid overlapping Me.ChartControl1.ChartAreas(0).Axes(0).LabelFont.Angle = 45 |
To write the code in C#
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
//create the series GrapeCity.ActiveReports.Chart.Series series = new GrapeCity.ActiveReports.Chart.Series(); series.Type = GrapeCity.ActiveReports.Chart.ChartType.Bar3D; //connection string and data adapter string dbPath = "C:\Users\YourUserName\Documents\GrapeCity Samples\ActiveReports 11\Data\NWIND.MDB"; string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dbPath; System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter ("SELECT * from Orders WHERE OrderDate < #08/17/1994#", connString); // create the dataset System.Data.DataSet ds = new System.Data.DataSet(); da.Fill(ds, "Orders"); // set chart properties this.chartControl1.DataSource = ds; this.chartControl1.Series.Add(series); this.chartControl1.Series[0].ValueMembersY = ds.Tables["Orders"].Columns[7].ColumnName; this.chartControl1.Series[0].ValueMemberX = ds.Tables["Orders"].Columns[8].ColumnName; // angle the labels to avoid overlapping this.chartControl1.ChartAreas[0].Axes[0].LabelFont.Angle = 45; |
To view the report
OR