Spread Windows Forms 10.0 Product Documentation
Binding the Chart Control

A series contains three parts (category, series name, and data). You can bind each part to an instance of the series data field. The entire chart control can not be bound; however, you can use a cell range or a formula to put data in the chart.

Using Code

You can add values to Spread with an array or dataset and then use a cell range to put those values in a chart control. This example uses an array to put data in the control.

Example

C#
Copy Code
private void Form1_Load(object sender, System.EventArgs e)
{
object[,] values = { { "lg1", "lg2", "lg3" }, { "tt1", 2.0, 5.0 }, {"tt2",4.0,5.0 } };
fpSpread1.Sheets[0].SetArray(0, 0, values);
FarPoint.Win.Spread.Model.CellRange cellRange = new FarPoint.Win.Spread.Model.CellRange(0,0,values.GetLength(0),values.GetLength(1));
fpSpread1.Sheets[0].AddChart(cellRange, typeof(FarPoint.Win.Chart.BarSeries), 400, 400, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
FarPoint.Win.Chart.BarSeries series = (FarPoint.Win.Chart.BarSeries)fpSpread1.Sheets[0].Charts[0].Model.PlotAreas[0].Series[0];
FarPoint.Win.Spread.Chart.SeriesDataField data = (FarPoint.Win.Spread.Chart.SeriesDataField)series.Values.DataSource;
data.Formula = "Sheet1!$B$2:$E$1";
}
VB
Copy Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim values As Object(,) = {{"lg1", "lg2", "lg3"}, {"tt1", 2.0R, 5.0R}, {"tt2", 4.0R, 5.0R}}
FpSpread1.Sheets(0).SetArray(0, 0, values)
Dim cellRange As New FarPoint.Win.Spread.Model.CellRange(0, 0, values.GetLength(0), values.GetLength(1))
FpSpread1.Sheets(0).AddChart(cellRange, GetType(FarPoint.Win.Chart.BarSeries), 400, 400, 0, 0)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim series As FarPoint.Win.Chart.BarSeries = DirectCast(FpSpread1.Sheets(0).Charts(0).Model.PlotAreas(0).Series(0), FarPoint.Win.Chart.BarSeries)
Dim data As FarPoint.Win.Spread.Chart.SeriesDataField = DirectCast(series.Values.DataSource, FarPoint.Win.Spread.Chart.SeriesDataField)
data.Formula = "Sheet1!$B$2:$E$1"
End Sub

Using Code

You can add values to Spread with an array or dataset and then use a cell range to put those values in a chart control. This example uses a data table to put data in the control.

Example

C#
Copy Code
DataTable dt = new DataTable("Test");
DataRow dr = default(DataRow);
dt.Columns.Add("Series1");
dt.Columns.Add("Series2");
dr = dt.NewRow();
dr[0] = 1;
dr[1] = 4;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = 5;
dr = dt.NewRow();
dt.Rows.Add(dr);
dr[0] = 3;
dr[1] = 6;
dt.Rows.Add(dr);
fpSpread1.DataSource = dt;
FarPoint.Win.Spread.Model.CellRange cellRange = new FarPoint.Win.Spread.Model.CellRange(0,0,2,2);
fpSpread1.Sheets[0].AddChart(cellRange, typeof(FarPoint.Win.Chart.BarSeries), 400,400,0,0); 
VB
Copy Code
Dim dt As New DataTable("Test")
Dim dr As DataRow
dt.Columns.Add("Series1")
dt.Columns.Add("Series2")
dr = dt.NewRow()
dr(0) = 1
dr(1) = 4
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 2
dr(1) = 5
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = 3
dr(1) = 6
dt.Rows.Add(dr)
FpSpread1.DataSource = dt
Dim cellRange As New FarPoint.Win.Spread.Model.CellRange(0, 0, 2, 2)
FpSpread1.Sheets(0).AddChart(cellRange, GetType(FarPoint.Win.Chart.BarSeries), 400, 400, 0, 0) 
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback