$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Chart Control for C# Windows Forms
Bind Chart to database like MS SQL, Oracle, MySQL, Access ODBC and XML data
Home > WinForms UI Controls > User Manual > Chart Data Binding in C#

Data Binding of Chart in WinForms C# Tutorial

The WinForms Chart control provides the support of data binding for designing the user interface in Windows Forms. The Chart control is compatible with the standard Windows Forms data binding model and allows bind the charts to any custom business object, database or declarative data source. This Chart can be bound to a wide variety of data sources and business objects, including MS SQL, Oracle, MySQL, Access ODBC as well as XML data. The data source must implement IEnumerable interface in general. What’s more, developers can customize the binding of WinForms Chart control by using ITypedList, ICustomTypeDescriptor, and INotifyPropertyChange interfaces with business objects.

Data Binding Interfaces and Properties for Chart

WinForms Chart control is compatible with the standard data binding model in Windows Forms. This Chart control support of data binding to any data source with implementing one of the following interfaces:
  • IListSource, the interface can be used for Data Table and Data Set classes.
  • IList, the interface can be used for 1D arrays.
  • IBindingList, the interface can be used for the generic Binding List class.
  • IBindingListView, the interface can be used for Binding Source class.
The following are the series types and the properties that may be used for data binding and the data binding will be processed on the descendant of Chart Series.
  • BarSeries , the bar series require the properties of DataSource and ValueMember to data binding. However, the property, CategoryMember, is optional and it may be numerated automatically when it is not set
  • AreaSeries , the Area series require the properties of DataSource and ValueMember to data binding. The CategoryMember property is optional and it may be numerated automatically when it is not set.
  • LineSeries , the Line series require the properties of DataSource and ValueMember to data binding. The CategoryMember property is optional and it may be numerated automatically when it is not set.
  • ScatterSeries , the Scatter Series require the properties of DataSource, XValueMember and YValueMember.
  • RadarSeries , the Radar series require the properties of DataSource and ValueMember to data binding. The CategoryMember property is optional and it may be numerated automatically when it is not set.
  • PieSeries , the Radar series require the properties of DataSource and ValueMember.
  • PolarSeries , the Polar series require the properties of DataSource, AngleMember and ValueMember.

How to Bind Chart to DataTable

The WinForms Chart control allows users binding to DataTable really easy. Developers can set the necessary members to the desired fields when the table is created. The following C# code shows how to bind data to Line Series.

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

table = new DataTable();
table.Columns.Add("Age", typeof(double));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(17, "Mark");
table.Rows.Add(13, "Simon");
table.Rows.Add(16, "Matt");
table.Rows.Add(14, "Jeff");
table.Rows.Add(16, "Mary");

LineSeries lineSeria = new LineSeries();
chart1.Series.Add(lineSeria);

lineSeria.ValueMember = "Age";
lineSeria.CategoryMember = "Name";
lineSeria.DataSource = table;
}

How to Bind Data to BindingList

The WinForms Chart control support of binding data to BindingList, and the binding list is a generic list type in which additional control over list items included. The binding list can be edited, removed or added. The following sample illustrates how to create a list of MyCustomObject, initializes the list and assigns it to the Bar Series object in Chart control for Windows Forms applications.
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls