Binding the Chart Directly to the Data Source

In most cases, data needs to be summarized before it can be charted, so there is a layer between the data source and the actual chart. In some cases, however, the data you want to plot may already be available in a DataView or similar data source object. In these cases, you can bind the chart directly to the data source object.

To bind a C1Chart control to a data source, you should start by setting the control's DataSource property to a data source object such as a DataView or DataTable. Then bind individual series to columns on the data source object using the DataSeries.X.DataField and DataSeries.Y.DataField properties.

You can do all this using the Chart Wizard, but if you prefer to do it in code here is a sample that demonstrates the entire process:

      Visual Basic

      C#

The code retrieves the NWind Products table, then creates two data series, each bound to a column on the data source.

The most interesting part of the bound table is that it maintains a dynamic connection to the data source. Any changes applied to the data source, including value changes, filters, sorting, new or deleted records, and so on, are automatically reflected on the chart.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.