Chart for .NET / User's Guide / Data Manipulation / Importing / Importing from DataTable and DataView

In This Topic
    Importing from DataTable and DataView
    In This Topic

    The data contained in the data series can be imported from a DataTable or DataView. This functionality is exposed to the user via the FillFromDataTable and FillFromDataView methods of the NDataSeries and NDataSeriesCollection classes.

    Please note that importing is different from data binding. Importing is a one-time operation, while Data Binding is a permanent relation between a data source and a series. For more information regarding data binding, please refer to the Data Binding topic.

     Importing a single DataTable column into a data series

    The user can import the data contained in a DataTable column with the help of the FillFromDataTable method of the NDataSeries class. The method receives two arguments - the data table and the column, which must be imported. The data contained in the specified column must be compatible with the data series type (see the General Concepts topic for a more detailed description of data series compatibility).

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

    C#
    Copy Code
    bar.Values.FillFromDataTable(Table1, "Values");
    
    Visual Basic
    Copy Code
    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 NDataSeriesCollection . This is achieved with the help of the FillFromDataTable method of the NDataSeriesCollection class. The method receives two arguments - the data table and the columns, which 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. The example code simultaneously imports the Values and Labels (of type string) columns into the Values and Labels data series of a bar chart.

    C#
    Copy Code
    // create a NDataSeriesCollection object
    NDataSeriesCollection arrSeries = bar.GetDataSeries(DataSeriesMask.Values |
    DataSeriesMask.Labels, DataSeriesMask.None);
    
    // create a string array containing the columns which must be imported
    string[] arrCollumns = { "Values", "Labels" };
    
    // import the columns into the data series
    arrSeries.FillFromDataTable(Table1, arrCollumns);
    
    Visual Basic
    Copy Code
    ' create a NDataSeriesCollection
    object Dim arrSeries As NDataSeriesCollection = bar.GetDataSeries(DataSeriesMask.Values
    Or DataSeriesMask.Labels, DataSeriesMask.None)
    
    ' create a string array containing the columns which must be imported
    Dim arrCollumns() As String = {"Values", "Labels"}
    
    ' import the columns into the data series
    arrSeries.FillFromDataTable(Table1, arrCollumns)
    
     Importing from a DataView

    Similarly to the FillFromDataTable methods of the NDataSeries and NDataSeriesCollection classes the FillFromDataView methods can be used to import data from a DataView source.

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

     Related Examples
    Windows forms: All Examples\Data Manipulation\Importing\From DataTable and DataView
    See Also