The Chart control has its own data source which is distinct from the report data source. To access the chart's data source, click the Data Source verb which appears below the Properties window when the chart is selected on the report. If the Data Source verb does not appear, see Access the Chart Wizard and Data Source for help.
The Chart control allows you to set the data source for a chart control, series, or data points collection at run time.
Any of the following objects can be used as data sources:
Below are some examples of binding to different data sources at run time.
The Chart control's DataSource property can be set to a dataset at run time. The following code demonstrates how to set up a dataset, set the DataSource property to the dataset, create a series, and set the ValueMembersY property to the dataset expression at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series Dim m_cnnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.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 dataset Dim oDS As DataSet oDBAdapter = New System.Data.OleDb.OleDbDataAdapter("SELECT ShipCountry, SUM(Freight) AS Expr1 FROM Orders GROUP BY ShipCountry", m_cnnString) oDS = New DataSet oDBAdapter.Fill(oDS, "Expr1") ' set the DataSource and ValueMembersY properties Me.ChartControl1.DataSource = oDS s.ValueMembersY = "Expr1" Me.ChartControl1.Series.Add(s) |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the series DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); string m_cnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.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 dataset System.Data.DataSet oDS; oDBAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT ShipCountry, SUM(Freight) AS Expr1 FROM Orders GROUP BY ShipCountry", m_cnnString); oDS = new System.Data.DataSet(); oDBAdapter.Fill(oDS, "Expr1"); // set the DataSource and ValueMembersY properties this.chartControl1.DataSource = oDS; s.ValueMembersY = "Expr1"; this.chartControl1.Series.Add(s); |
In the Chart control, the ValueMembersX and ValueMembersY properties of a series can be set to a dataset column. The following code demonstrates how to create a series, set up a dataset, set the DataSource property to the dataset, and set the ValueMembersY and ValueMembersX properties to dataset columns at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series Dim m_cnnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.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 dataset 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.ChartControl1.DataSource = oDS Me.ChartControl1.Series.Add(s) Me.ChartControl1.Series(0).ValueMembersY = oDS.Tables("Orders").Columns(7).ColumnName Me.ChartControl1.Series(0).ValueMemberX = oDS.Tables("Orders").Columns(8).ColumnName |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the series DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); string m_cnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.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 dataset 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.chartControl1.DataSource = oDS; this.chartControl1.Series.Add(s); this.chartControl1.Series[0].ValueMembersY = oDS.Tables["Orders"].Columns[7].ColumnName; this.chartControl1.Series[0].ValueMemberX = oDS.Tables["Orders"].Columns[8].ColumnName; |
You can set a chart's data source to a SqlCommand or OleDbCommand. The following code demonstrates how to create a series, create an OleDbCommand, set the DataSource property to the data command, and set the ValueMembersY property for the series at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series Dim m_cnnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.mdb; Persist Security Info=False" Dim m_cnn As New System.Data.Oledb.OleDbConnection(m_cnnString) Dim query As String = "SELECT ShipCountry, SUM(Freight) AS Expr1 FROM Orders GROUP BY ShipCountry" ' create the OleDbCommand and open the connection Dim command As New System.Data.Oledb.OleDbCommand(query, m_cnn) command.Connection.Open() ' set the DataSource and ValueMembersY properties Me.ChartControl1.DataSource = command Me.ChartControl1.Series.Add(s) Me.ChartControl1.Series(0).ValueMembersY = "Expr1" ' close the connection m_cnn.Close() |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the series DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); string m_cnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Northwind.mdb;Persist Security Info=False"; System.Data.Oledb.OleDbConnection m_cnn = new System.Data.Oledb.OleDbConnection(m_cnnString); string query = "SELECT ShipCountry, SUM(Freight) AS Expr1 FROM Orders GROUP BY ShipCountry"; // create the OleDbCommand and opent the connection System.Data.Oledb.OleDbCommand command = new System.Data.Oledb.OleDbCommand(query, m_cnn); command.Connection.Open(); // set the DataSource and ValueMembersY properties this.chartControl1.DataSource = command; this.chartControl1.Series.Add(s); this.chartControl1.Series[0].ValueMembersY = "Expr1"; // close the connection m_cnn.Close(); |
The Chart control allows you to set the data source for the data points collection to an array. The following code demonstrates how to create a series, create an array, and use the DataBindY method to set the data source for the data points collection at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series ' create the array Dim a As Double() = {1, 4, 2, 6, 3, 3, 4, 7} ' set the data source for the data points collection Me.ChartControl1.Series.Add(s) Me.ChartControl1.Series(0).Points.DataBindY(a) |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the series DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); // create the array double [] a = {1,4,2,6,3,3,4,7}; // set the data source for the data points collection this.chartControl1.Series.Add(s); this.chartControl1.Series[0].Points.DataBindY(a); |
You can easily create a calculated series based on the values of one or more series by setting the ValueMembersY property of a series to a formula. To reference a series in the formula, use the name of the series. The following code demonstrates how to create two series, one bound to a data array and the other bound to a formula based on the Y values of the first series.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the FetchData event. |
Copy Code |
---|---|
Dim s As New DataDynamics.ActiveReports.Chart.Series Dim cS As New DataDynamics.ActiveReports.Chart.Series Dim a As Double() = {1, 4, 2, 6, 3, 3, 4, 7} Me.ChartControl1.Series.AddRange(New DataDynamics.ActiveReports.Chart.Series() {s, cS}) Me.ChartControl1.Series(0).Points.DataBindY(a) Me.ChartControl1.Series(0).Name = "Series1" Me.ChartControl1.Series(1).ValueMembersY = "Series1.Y[0]+10" |
To write the code in C#
C# code. Paste INSIDE the FetchData event. |
Copy Code |
---|---|
DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); DataDynamics.ActiveReports.Chart.Series cS = new DataDynamics.ActiveReports.Chart.Series(); double [] a = { 1,4,2,6,3,3,4,7}; this.chartControl1.Series.AddRange(new DataDynamics.ActiveReports.Chart.Series[] {s, cS}); this.chartControl1.Series[0].Name = "Series1"; this.chartControl1.Series[0].Points.DataBindY(a); this.chartControl1.Series[1].ValueMembersY = "Series1.Y[0]+10"; |
Set a sequence series by specifying the minimum value, maximum value, and step for the series. The following code shows how to set the ValueMembersY property at run time to create a sequence series.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
Dim s As New DataDynamics.ActiveReports.Chart.Series Me.ChartControl1.Series.Add(s) Me.ChartControl1.Series(0).ValueMembersY = "sequence(12,48,4)" |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); this.chartControl1.Series.Add(s); this.chartControl1.Series[0].ValueMembersY = "sequence(12,48,4)"; |
The Chart control allows you to set the data source to an XML document. The following code demonstrates how to create a series and to set the ValueMembersY and ValueMemberX properties at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
' create the series Dim s As New DataDynamics.ActiveReports.Chart.Series() Dim xmlDS As New DataDynamics.ActiveReports.DataSources.XMLDataSource("c:/customer.xml", "//CUSTOMER") ' set the DataSource, ValueMembersY and ValueMemberX properties Me.ChartControl1.DataSource = xmlDS Me.ChartControl1.Series.Add(s) Me.ChartControl1.Series(0).ValueMembersY = "xpath:ORDER/ITEM/PRICE" Me.ChartControl1.Series(0).ValueMemberX = "xpath:ORDER/ITEM/AUTHOR" |
To write the code in C#
C# code. Paste INSIDE the section Format event. |
Copy Code |
---|---|
// create the series |