[]
        
(Showing Draft Content)

Using a Bound Data Source

You can bind the chart to the following data sources:

  • Array

  • Array List (IList)

  • List Collection

  • Table

When the chart is bound to data, it dynamically plots the data when it paints. A single chart can support (and display) data from multiple data sources and multiple data fields within a data source.

For information on binding to a data source, see the members of the class that represents the data series of interest (for example, the BarSeries class for bar charts).

Example

The following example demonstrates how to bind a bar chart to array data.

// Create an array and bind.
object[] values = new object[] { 2, 4.0, 3.0m, "5.0" };
BarSeries series = new BarSeries();
series.Values.DataSource = values;
' Create an array and bind.
Dim values() As Object = {2, 4.0, 3.0D, "5.0"}
Dim series As New BarSeries()
series.Values.DataSource = values

The following example demonstrates how to bind a bar chart to table.

DataTable dt = new DataTable("Test");
DataRow dr = default(DataRow);
dt.Columns.Add("Series0");
dt.Columns.Add("Series1");
dr = dt.NewRow();
dr[0] = 2;
dr[1] = 1;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 4;
dr[1] = 2;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 3;
dr[1] = 4;
FarPoint.Win.Chart.BarSeries series = new FarPoint.Win.Chart.BarSeries();
series.Values.DataSource = dt;
series.Values.DataField = dt.Columns[0].ColumnName;
FarPoint.Win.Chart.YPlotArea plotArea = new FarPoint.Win.Chart.YPlotArea();
FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();
plotArea.Location = new PointF(0.2F, 0.2F);
plotArea.Size = new SizeF(0.6F, 0.6F);
plotArea.Series.Add(series);
model.PlotAreas.Add(plotArea);
fpChart1.Model = model;
Dim dt As New DataTable("Test")
Dim dr As DataRow
dt.Columns.Add("Series0")
dt.Columns.Add("Series1")
dr = dt.NewRow()
dr(0) = 2
dr(1) = 1
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 4
dr(1) = 2
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 3
dr(1) = 4
dt.Rows.Add(dr)
Dim series As New FarPoint.Win.Chart.BarSeries
series.Values.DataSource = dt
series.Values.DataField = dt.Columns(0).ColumnName
Dim model As New FarPoint.Win.Chart.ChartModel()
Dim plotArea As New FarPoint.Win.Chart.YPlotArea()
plotArea.Location = New PointF(0.2F, 0.2F)
plotArea.Size = New SizeF(0.6F, 0.6F)
plotArea.Series.Add(series)
model.PlotAreas.Add(plotArea)
FpChart1.Model = model

See Also

Using an UnBound Data Source

Binding with cell range