ActiveReports for .NET 3 Online Help Request technical support
Unbound Chart
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Unbound Reports > Unbound Chart

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.
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 your 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 rptUnboundChart.
  4. Click Open.

Adding the chart control to the report

To add a chart control to the report

  1. Click the ChartControl in the ActiveReports toolbox and draw it onto the report surface.
  2. With the chart control highlighted, click the Customize verb below the Properties Window to open the Chart Designer dialog. 
    If you do not see the verbs in Visual Studio 2005, right-click the Properties Window and select Commands
  3. Click the Series button on the left side, and delete Series1, Series2, and Series3.
  4. Click the Titles button on the left side of the Chart Designer.
  5. Type Unbound Chart in the header title Caption and increase the font size to 14.
  6. Delete the footer title.
  7. Click the ChartAreas button on the left side of the wizard, and expand the Axes button.
  8. Click AxisX to select it, enter Company Name in the AxisX Title and increase the font size to 12.
  9. Click AxisY to select it, enter Freight in US$ in the AxisY Title and increase the font size to 12.
  10. Click the Legends button on the left side of the Chart Designer.
  11. Clear the Visible check box at the top.
  12. Click Finish.

Adding code to connect the chart to a data source

To write the code in Visual Basic or C#

The following example shows what the code for the method looks like.

'Visual Basic
'Set the database path
Private Function getDatabasePath() As String
   Dim regKey As Microsoft.Win32.RegistryKey
   regKey = Microsoft.Win32.Registry.LocalMachine
   regKey = regKey.CreateSubKey _
   ("SOFTWARE\\Data Dynamics\\ActiveReports for .NET 3.0\\SampleDB")
   getDatabasePath = CType(regKey.GetValue(""), String)
End Function

Private Sub rptUnboundChart_ReportStart(ByVal sender As Object, ByVal e As System _
	.EventArgs) Handles MyBase.ReportStart
    '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
End Sub

 

//C#
//Set the database path
private string getDatabasePath()
{
   Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine;
   regKey = regKey.CreateSubKey("SOFTWARE\\Data Dynamics\\ActiveReports for .NET 3.0\\SampleDB");
   return ((string)(regKey.GetValue(""))); 
}

private void rptUnboundChart_ReportStart(object sender, System.EventArgs eArgs)
{
   //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;
}

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.