Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Data Manipulation / Importing / Importing from DataTable and DataView

In This Topic
    Importing from DataTable and DataView
    In This Topic

    The data contained in a data series can be imported from DataTable or DataView objects. This functionality is exposed to the user via the FillFromDataTable and FillFromDataView methods of the DataSeries and DataSeriesCollection classes. These methods will be discussed below.

    Importing a Single DataTable Column into a Data Series

    The user can import the data contained in a DataTable column with the FillFromDataTable method of the DataSeries class. The method receives two arguments: the data table and the column that must be imported. The data contained in the specified column must be compatible with the data series type. See the General Concepts and Terminology topic for a more detailed description of data series compatibility. 

    The following example demonstrates a single data series import from a DataTable object. The example assumes that the DataTable Table1 has a column called Values which is of type double.

    VB.NET  
    bar.Values.FillFromDataTable(Table1, "Values")
    C#  
    bar.Values.FillFromDataTable(Table1, "Values");

    Importing Multiple DataTable Columns into a Data Series Collection

    The user can simultaneously import the data contained in a set of DataTable columns into the data series contained in a DataSeriesCollection. This is achieved by using the FillFromDataTable method of the DataSeriesCollection class. The method receives two arguments: the data table and the columns that must be imported. The first specified column is imported into the first data series, the second column into the second series, etc. 

    The following example demonstrates a multiple data series import from a DataTable object. The example code simultaneously imports the Values and Labels columns (of type string) into the Values and Labels data series of a bar chart.

    VB.NET  

    ' create a DataSeriesCollection

    object Dim arrSeries As DataSeriesCollection = bar.GetDataSeries(DataSeriesMask.Values Or

    DataSeriesMask.Labels, DataSeriesMask.None)

     

    ' create a string array containing the columns which must be imported

    Dim arrColumns() As String = {"Values", "Labels"}

     

    ' import the columns into the data series

    arrSeries.FillFromDataTable(Table1, arrColumns)

    C#  
    // create a DataSeriesCollection object
    DataSeriesCollection arrSeries = bar.GetDataSeries(DataSeriesMask.Values | DataSeriesMask.Labels, DataSeriesMask.None, true );
    // create a string array containing the columns which must be imported
    string[] arrColumns = { "Values", "Labels" };
    // import the columns into the data series
    arrSeries.FillFromDataTable(Table1, arrColumns);

    Importing from a DataView

    Analogously to the FillFromDataTable methods of the DataSeries and DataSeriesCollection classes, the DataSeries. FillFromDataView and DataSeriesCollection. FillFromDataView methods of the same classes can be used to import the data series data from a DataView source. 

    Even though a DataView object internally uses a DataTable source, the import from a DataView object feature is useful because the imported data will be synchronized with the applied DataView sorting and filtering.

    Related Examples

    Windows Forms: Data Manipulation\Importing\From DataTable and DataView

    See Also

    Basic Series Functionality | DataSeries | DataSeriesCollection