[]
        
(Showing Draft Content)

Step 2: Binding FinancialChart to a Data Source

After you have added FinancialChart to the form, you need to bind the control to a valid data source.


The following code snippet demonstrates how you can bind FinancialChart to a data source and display the data from the same. You just need to enter the given code in the Form_Load event.


Private Sub Form1_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load
    ' create a data table
    Dim dt As New DataTable()
    ' add columns to the data table
    dt.Columns.Add("Date", GetType(String))
    dt.Columns.Add("Stock Price", GetType(Integer))
    ' add rows to the data table
    dt.Rows.Add("Jan 1", 190)
    dt.Rows.Add("Jan 8", 210)
    dt.Rows.Add("Jan 15", 150)
    dt.Rows.Add("Jan 22", 170)
    dt.Rows.Add("Jan 29", 220)
    dt.Rows.Add("Feb 5", 250)
    dt.Rows.Add("Feb 12", 230)
    dt.Rows.Add("Feb 26", 270)
    ' create a data series
    Dim series1 As New C1.Win.Chart.Series()
    ' add the series to the Series collection of FinancialChart
    FinancialChart1.Series.Add(series1)
    ' bind FinancialChart to the data table
    FinancialChart1.DataSource = dt
    ' bind X-axis of FinancialChart
    FinancialChart1.BindingX = "Date"
    ' bind Y-axis of FinancialChart
    FinancialChart1.Binding = "Stock Price"
    ' set the chart type
    FinancialChart1.ChartType = C1.Chart.Finance.FinancialChartType.Line
End Sub
private void Form1_Load(object sender, EventArgs e)
{
    // create a data table
    DataTable dt = new DataTable();
    // add columns to the data table
    dt.Columns.Add("Date", typeof(string));
    dt.Columns.Add("Stock Price", typeof(int));
    // add rows to the data table
    dt.Rows.Add("Jan 1", 190);
    dt.Rows.Add("Jan 8", 210);
    dt.Rows.Add("Jan 15", 150);
    dt.Rows.Add("Jan 22", 170);
    dt.Rows.Add("Jan 29", 220);
    dt.Rows.Add("Feb 5", 250);
    dt.Rows.Add("Feb 12", 230);
    dt.Rows.Add("Feb 26", 270);
    // create a data series
    C1.Win.Chart.Series series1 = new C1.Win.Chart.Series();
    // add the series to the Series collection of FinancialChart
    financialChart1.Series.Add(series1);
    // bind FinancialChart to the data table
    financialChart1.DataSource = dt;
    // bind X-axis of FinancialChart
    financialChart1.BindingX = "Date";
    // bind Y-axis of FinancialChart
    financialChart1.Binding = "Stock Price";
    // set the chart type
    financialChart1.ChartType = C1.Chart.Finance.FinancialChartType.Line;
}