Spread ASP.NET 16
Spread for ASP.NET 16 Product Documentation / Developer's Guide / Working with the Chart Control / Creating Charts / Connecting to Data / Using a Bound Data Source
In This Topic
    Using a Bound Data Source
    In This Topic

    You can bind the chart to the following data sources.

    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 more information about the DataSource property, refer to the specific chart type in the Assembly Reference (for example: SeriesNameDataSource in the RadarLineSeries class).

    Using Code

    Use the Values property of the series to add a data source.

    Example

    The following example demonstrates how to bind the control to a data source.

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

    Using Code

    Use the Values property of the series to add a data source.

    Example

    The following example demonstrates how to bind the control to a data table.

    C#
    Copy Code
    System.Data.DataTable dt = new System.Data.DataTable("Test");
    System.Data.DataRow dr = default(System.Data.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.Web.Chart.BarSeries series = new FarPoint.Web.Chart.BarSeries();
    series.Values.DataSource = dt;
    series.Values.DataField = dt.Columns[0].ColumnName;
    FarPoint.Web.Chart.YPlotArea plotArea = new FarPoint.Web.Chart.YPlotArea();
    FarPoint.Web.Chart.ChartModel model = new FarPoint.Web.Chart.ChartModel();
    plotArea.Location = new System.Drawing.PointF(0.2F, 0.2F);
    plotArea.Size = new System.Drawing.SizeF(0.6F, 0.6F);
    plotArea.Series.Add(series);
    model.PlotAreas.Add(plotArea);
    FarPoint.Web.Spread.Chart.SpreadChart chart = new FarPoint.Web.Spread.Chart.SpreadChart();
    chart.Model = model;
    FpSpread1.Sheets[0].Charts.Add(chart);
    
    VB
    Copy Code
    Dim dt As New System.Data.DataTable("Test")
    Dim dr As System.Data.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.Web.Chart.BarSeries
    series.Values.DataSource = dt
    series.Values.DataField = dt.Columns(0).ColumnName
    Dim model As New FarPoint.Web.Chart.ChartModel()
    Dim plotArea As New FarPoint.Web.Chart.YPlotArea()
    plotArea.Location = New System.Drawing.PointF(0.2F, 0.2F)
    plotArea.Size = New System.Drawing.SizeF(0.6F, 0.6F)
    plotArea.Series.Add(series)
    model.PlotAreas.Add(plotArea)
    Dim chart As New FarPoint.Web.Spread.Chart.SpreadChart()
    chart.Model = model
    FpSpread1.Sheets(0).Charts.Add(chart)