Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Data Manipulation / Binding

In This Topic
    Binding
    In This Topic

    The data contained in the data series can be bound to DataAdapters and DataSets. This functionality is exposed to the user via the ColumnName and IsBind properties of the DataSeries class, the DataSourceIndex property of the Chart class, and with the DataBindingManager class.

    Binding a Chart to a Data Source

    The data sources are added by using the AddDataSource method of the DataBindingManager class. With the DataSourceIndex property of the Chart class, set the index of the data source that you want to bind to the chart. With the ColumnName and IsBind properties of the DataSeries class, set the column name of the data source bound to the data series and specify whether DataBinding is enabled for the data series. In order to update chart control form data sources, you call the UpdateFromDataSources method of the chart control.

    The following examples bind a chart series to an OleDbDataAdapter.

    VB.NET  

    ...

    ' add data source to chart control

    Dim index As Integer = ChartControl.DataBindingManager.AddDataSource(oleDbDataAdapter1)

     

    ' set data source index

    chart.DataSourceIndex = index

     

    ' get chart series

    Dim bar As BarSeries = CType(chart.Series(0), BarSeries)

     

    ' data series "Values" is bind to column name "values"

    bar.Values.ColumnName = "values"

    bar.Values.IsBind = True

     

    ' data series "Labels" is bind to column name "colors"

    bar.Labels.ColumnName = "colors"

    bar.Labels.IsBind = True

     

    ' data series "FillEffects" is bind to column name "colors"

    bar.Appearance.FillEffects.ColumnName = "colors"

    bar.Appearance.FillEffects.IsBind = True

     

    ChartControl.UpdateFromDataSources()

    C#  

    ...

    // add data source to chart control

    int index = ChartControl.DataBindingManager.AddDataSource(oleDbDataAdapter1);

     

    // set data source index

    chart.DataSourceIndex = index;

     

    // get chart series

    BarSeries bar = (BarSeries)chart.Series[0];

     

    // data series "Values" is bind to column name "values"

    bar.Values.ColumnName = "values";

    bar.Values.IsBind = true;

     

    // data series "Labels" is bind to column name "colors"

    bar.Labels.ColumnName = "colors";

    bar.Labels.IsBind = true;

     

    // data series "FillEffects" is bind to column name "colors"

    bar.Appearance.FillEffects.ColumnName = "colors";

    bar.Appearance.FillEffects.IsBind = true;

     

    ChartControl.UpdateFromDataSources();

    See Also

    DataBinding Wizard