Glossary Item Box
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 then 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:
To complete the walkthrough, you must have access to the NorthWind database (Nwind.mdb).
When you have finished this walkthrough, you will have a report that looks similar to the following.
To create a new Visual Studio project
Click on File > New > Project.
To add an ActiveReport to your project
To add a chart control to the report
To write the code in Visual Basic
To write the code in C#
The following example shows what the code for the method looks like.
' Visual Basic Private Sub rptUnboundChart_ReportStart(ByVal sender As Object, ByVal e As System _ .EventArgs) Handles MyBase.ReportStart ' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series s.Type = Chart.ChartType.Bar3D Dim m_cnnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= _ C:/NWIND.MDB;Persist Security Info=False" Dim m_cnn As New System.Data.OleDb.OleDbConnection(m_cnnString) Dim oDBAdapter As System.Data.OleDb.OleDbDataAdapter ' create the data set Dim oDS As DataSet oDBAdapter = New System.Data.OleDb.OleDbDataAdapter("SELECT * from Orders WHERE _ OrderDate < #08/17/1994#", m_cnnString) oDS = New DataSet oDBAdapter.Fill(oDS, "Orders") ' set the DataSource, ValueMembersY, and ValueMembersX properties Me.chtUnbound.DataSource = oDS Me.chtUnbound.Series.Add(s) Me.chtUnbound.Series(0).ValueMembersY = oDS.Tables("Orders").Columns(7).ColumnName Me.chtUnbound.Series(0).ValueMemberX = oDS.Tables("Orders").Columns(8).ColumnName ' angle the labels to avoid overlapping Me.chtUnbound.ChartAreas(0).Axes(0).LabelFont.Angle = 90 End Sub
//C# private void rptUnboundChart_ReportStart(object sender, System.EventArgs eArgs) { // create the series DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart .Series(); s.Type = DataDynamics.ActiveReports.Chart.ChartType.Bar3D; string m_cnnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/NWIND.MDB; Persist Security Info=False"; System.Data.OleDb.OleDbConnection m_cnn = new System.Data.OleDb.OleDbConnection (m_cnnString); System.Data.OleDb.OleDbDataAdapter oDBAdapter; // create the data set System.Data.DataSet oDS; oDBAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * from Orders WHERE OrderDate < #08/17/1994#", m_cnnString); oDS = new System.Data.DataSet(); oDBAdapter.Fill(oDS, "Orders"); // set the DataSource, ValueMembersY, and ValueMembersX properties this.chtUnbound.DataSource = oDS; this.chtUnbound.Series.Add(s); this.chtUnbound.Series[0].ValueMembersY = oDS.Tables["Orders"].Columns[7] .ColumnName; this.chtUnbound.Series[0].ValueMemberX = oDS.Tables["Orders"].Columns[8] .ColumnName; // angle the labels to avoid overlapping this.chtUnbound.ChartAreas[0].Axes[0].LabelFont.Angle = 90; }
To view the report
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.