Load Chart data from the Data Table
C# sample solution.
Visual Basic .NET sample solution.

Manco.Chart for .NET have very flexible data load model that allows using literally any data source for charting. All what you need is create data provider class that allows obtaining of values by its category and series number. The Manco.Chart for .NET provides data source classes for the array of doubles, XML and data table.

Manco.Chart for .NET can accept data from the System.Data.DataTable object. You can select how series and categories are represented (located in the columns or rows). You can set up what columns will be included to the chart. To load data from the data table do following:

  1. Create DataTable object and fill it in with data. This data table can be part of the data set or standalone object as well.
  2. Prepare list of the category/series columns (depends on the data orientation).
    1. List<DataColumn> loColumns = new List<DataColumn>();
    2. Fill list with columns will be used for charting.
  3. Create chart data source using DataTableDataSource class:
    IChartDataSource loDataSource = 
    new DataTableDataSource(loDataTable, 
    	DataOrientation.CategoryInRow,
    	loDataTable.Columns[liSeriesCount],
    	loColumns,
    	lsFormat);
  4. Load data to the chart object:
    m_ChartControl.Charts[0].LoadData(loDataSource, false, true);

Second parameter (false) indicates that Category and Series lists will be recreated to have given number of the categories/series. Third parameter (true) indicates that all necessary regions of the chart should be invalidated. After that you can load theme to decorate chart or assign chart layout settings using API, and then draw chart.

The code that implements this sequence could looks like the following:

public void LoadDataTable()
{
	// Create data table
	DataTable loDataTable = new DataTable("ChartData");

	// Fill data table with data here.
	// Use DataAdapter.Fill, TableAdapter.Fill or something
        else
	// to fill data table with data.
	// ....

	// Column that will be used as category name
	DataColumn loCategoryName = null;

	// Create list of the columns will be used for charting
	List<DataColumn> loColumns = new List<DataColumn>();
	foreach(DataColumn loColumn in loDataTable.Columns)
	{
		// Check whether we should add column to the list
		// In this sample we exclude column that have DateTime type
		bool lbAddCondition = loColumn.DataType != typeof(DateTime);
		if (lbAddCondition)
		{
			loColumns.Add(loColumn);
		}
		else
		{
			// Column with DateTime tyoe will be used
			// as column with category name
			loCategoryName = loColumn;
		}
	}

	// Create IChartDataSource object
	// The "{0:hh:mm}" in the last parameter represents format 
	// for the category name
	IChartDataSource loDataSource = new DataTableDataSource(loDataTable, 
		DataOrientation.CategoryInRow,
		loCategoryName,
		loColumns,
		"{0:hh:mm}");

	// Load data to the chart
	m_ChartControl.Charts[0].LoadData(loDataSource, false, true);

	// Load theme to decorate chart or assign chart layout settings
        using API here
	// ...

	// Draw chart
	m_ChartControl.Draw();
}