New to Telerik UI for WinForms? Download free 30-day trial

Binding to DataTable

Binding to DataTable is quite easy with RadChartView. Once your table is created, you just need to set the needed members to the desired fields. In this article , you can find the members needed for the different series types.

Here is a sample demonstrating how to bind а LineSeries:

Binding to DataTable

DataTable table;
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    table = new DataTable();
    table.Columns.Add("Value", typeof(double));
    table.Columns.Add("Name", typeof(string));
    table.Rows.Add(1, "John");
    table.Rows.Add(3, "Adam");
    table.Rows.Add(5, "Peter");
    table.Rows.Add(12, "Sam");
    table.Rows.Add(6, "Paul");
    LineSeries lineSeria = new LineSeries();
    radChartView1.Series.Add(lineSeria);
    lineSeria.ValueMember = "Value";
    lineSeria.CategoryMember = "Name";
    lineSeria.DataSource = table;
}

Private table As DataTable
Protected Overrides Sub OnLoad(e As EventArgs)
    MyBase.OnLoad(e)
    table = New DataTable()
    table.Columns.Add("Value", GetType(Double))
    table.Columns.Add("Name", GetType(String))
    table.Rows.Add(1, "John")
    table.Rows.Add(3, "Adam")
    table.Rows.Add(5, "Peter")
    table.Rows.Add(12, "Sam")
    table.Rows.Add(6, "Paul")
    Dim lineSeria As New LineSeries()
    RadChartView1.Series.Add(lineSeria)
    lineSeria.ValueMember = "Value"
    lineSeria.CategoryMember = "Name"
    lineSeria.DataSource = table
End Sub

Figure 1: Binding to DataTable

WinForms RadChartView Binding to DataTable

Adding, removing or modifying a record in the DataTable is automatically reflected in RadChartView:

Figure 2: Modify Item

WinForms RadChartView Modify Item

See Also

In this article