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:
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.
Tip: If you do not see the verbs, right-click an empty space in the Properties Window and select Commands. |
Back on the design surface of the report, the chart appears empty except for the title.
Double-click in the gray area below rptUnbound. This creates an event-handling method for rptUnboundChart's ReportStart event. Add code to the handler to:
Important: Place this code above the ReportStart event. |
The following examples show what the code for the methods look like in Visual Basic.NET and C#.
Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. |
Copy Code |
---|---|
'Set the database path Private Function getDatabasePath() As String Dim regKey As Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine regKey = regKey.CreateSubKey("SOFTWARE\\GrapeCity\\ActiveReports 6\\SampleDB") getDatabasePath = CType(regKey.GetValue(""), String) End Function |
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code |
---|---|
'create the series Dim series As New DataDynamics.ActiveReports.Chart.Series series.Type = Chart.ChartType.Bar3D 'connection string and data adapter Dim dbPath As String = getDatabasePath() Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dbPath + "\\NWIND.mdb" 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 = 90 |
C# code. Paste JUST ABOVE the ReportStart event. |
Copy Code |
---|---|
//Set the database path private string getDatabasePath() { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine; regKey = regKey.CreateSubKey("SOFTWARE\\GrapeCity\\ActiveReports 6\\SampleDB"); return ((string)(regKey.GetValue(""))); } |
C# code. Paste INSIDE the ReportStart event. |
Copy Code |
---|---|
//create the series DataDynamics.ActiveReports.Chart.Series series = new DataDynamics.ActiveReports.Chart.Series(); series.Type = DataDynamics.ActiveReports.Chart.ChartType.Bar3D; //connection string and data adapter string dbPath = getDatabasePath(); string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + dbPath + "\\NWIND.mdb"; 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 = 90; |