Page 1 of 1
Datagrid - TChart Connecting - On with Event
Posted: Wed Apr 06, 2011 6:22 am
by 15658604
Hi,
I am using an TChart Controll to view some Data and i would like to display the data with an Datagrid in an secound form.
On witch event (like On afterAddSeries) is it possible to connect and Datagrid.Datasource with the TeeDatatable. (The Code in your Demo only show's it only at Series.Add) I am using the TEditor for Series.Add.
Thanks AGF
Re: Datagrid - TChart Connecting - On with Event
Posted: Wed Apr 06, 2011 9:55 am
by 10050769
Hello AGF,
I think you can do something as do in next code:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
DataGrid grid1;
Steema.TeeChart.Styles.Line series1;
Form2 myForm;
private void InitializeChart()
{
series1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
series1.FillSampleValues();
series1.AfterDrawValues += new Steema.TeeChart.PaintChartEventHandler(series1_AfterDrawValues);
}
void series1_AfterDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
grid1 = new DataGrid();
myForm = new Form2();
myForm.Controls.Add(grid1);
grid1.Width = 200;
grid1.Height = 300;
grid1.AllowSorting = false;
grid1.CaptionVisible = false;
grid1.DataSource = series1.DataSource;
}
private void button1_Click(object sender, EventArgs e)
{
grid1 = new DataGrid();
myForm.Show();
}
Where is linking grid1 with Form2 and grid1 with TeeDataSet of series1. Could you tell us if previous code works as you expected?
I hope will helps.
Thanks,
Re: Datagrid - TChart Connecting - On with Event
Posted: Wed Apr 06, 2011 4:16 pm
by 15658604
It works well with one series,
but if i have a couple of series not! How could i set an couple of series with data as Grid.Datasource?
Thanks
Re: Datagrid - TChart Connecting - On with Event
Posted: Thu Apr 07, 2011 10:18 am
by 10050769
Hello AGF,
Ok. I have made a new simple project using a
DataSet so you could add more than one set of data to a
Datagrid :
Code: Select all
Form2 myForm;
Steema.TeeChart.Styles.Line series1,series2;
private void InitializeChart()
{
series1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
series2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
series1.FillSampleValues(10);
series2.FillSampleValues(10);
CreateDataGrid();
}
private void CreateDataGrid()
{
//Creat DataGrid;
DataGrid dataGrid1 = new DataGrid();
myForm = new Form2();
myForm.Controls.Add(dataGrid1);
dataGrid1.Dock = DockStyle.Fill;
dataGrid1.SetDataBinding(GetData(), "TeeDataTable");
//Adding colums To data.
DataGridTextBoxColumn xColumn = new DataGridTextBoxColumn();
xColumn.MappingName = "X";
xColumn.HeaderText = "X";
DataGridTextBoxColumn yColumn = new DataGridTextBoxColumn();
yColumn.MappingName = "Y";
yColumn.HeaderText = "Y";
DataGridTextBoxColumn xColumn1 = new DataGridTextBoxColumn();
xColumn1.MappingName = "X1";
xColumn1.HeaderText = "X1";
DataGridTextBoxColumn yColumn1= new DataGridTextBoxColumn();
yColumn1.MappingName = "Y1";
yColumn1.HeaderText = "Y1";
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "TeeDataTable";
GridColumnStylesCollection columnStyles;
columnStyles = tableStyle.GridColumnStyles;
columnStyles.Add(xColumn);
columnStyles.Add(yColumn);
columnStyles.Add(xColumn1);
columnStyles.Add(yColumn1);
dataGrid1.TableStyles.Add(tableStyle);
}
private DataSet GetData()
{
DataSet TeeDataSet = new DataSet();
DataTable TeeDataTable = new DataTable("TeeDataTable");
DataRow newRow;
DataColumn xval = new DataColumn("X", typeof(double));
DataColumn yval = new DataColumn("Y", typeof(double));
DataColumn xval1 = new DataColumn("X1", typeof(double));
DataColumn yval1 = new DataColumn("Y1", typeof(double));
TeeDataTable.Columns.Add(xval);
TeeDataTable.Columns.Add(yval);
TeeDataTable.Columns.Add(xval1);
TeeDataTable.Columns.Add(yval1);
for (int i = 0; i < series1.Count; i++)
{
newRow = TeeDataTable.NewRow();
newRow[xval] = series1.XValues[i];
newRow[yval] = series1.YValues[i];
newRow[xval1] = series2.XValues[i];
newRow[yval1] = series2.YValues[i];
TeeDataTable.Rows.Add(newRow);
}
TeeDataSet.Tables.Add(TeeDataTable);
return TeeDataSet;
}
private void button1_Click(object sender, EventArgs e)
{
myForm.Show();
}
Could you confirm us if previous code works as you expected?
I hope will helps.
Thanks,
Re: Datagrid - TChart Connecting - On with Event
Posted: Fri Apr 08, 2011 6:22 am
by 15658604
Dear Sandra,
the principle is now clear. i have writen an loop witch work out all Series on the TChart, but i have Problems with
Code: Select all
DataColumn xval = new DataColumn("X", typeof(double));
in VB.Net syntax......
Thanks
Re: Datagrid - TChart Connecting - On with Event
Posted: Fri Apr 08, 2011 11:47 am
by 10050769
Hello AGF,
I have made the same example in .VB, please check if it works as you expected:
Code: Select all
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
InitializeChart()
End Sub
Private myForm As Form2
Private series1 As Steema.TeeChart.Styles.Line, series2 As Steema.TeeChart.Styles.Line
Private Sub InitializeChart()
series1 = New Steema.TeeChart.Styles.Line(TChart1.Chart)
series2 = New Steema.TeeChart.Styles.Line(TChart1.Chart)
series1.FillSampleValues(10)
series2.FillSampleValues(10)
CreateDataGrid()
End Sub
Private Sub CreateDataGrid()
'Creat DataGrid;
Dim dataGrid1 As New DataGrid()
myForm = New Form2()
myForm.Controls.Add(dataGrid1)
dataGrid1.Dock = DockStyle.Fill
dataGrid1.SetDataBinding(GetData(), "TeeDataTable")
'Adding colums To data.
Dim xColumn As New DataGridTextBoxColumn()
xColumn.MappingName = "X"
xColumn.HeaderText = "X"
Dim yColumn As New DataGridTextBoxColumn()
yColumn.MappingName = "Y"
yColumn.HeaderText = "Y"
Dim xColumn1 As New DataGridTextBoxColumn()
xColumn1.MappingName = "X1"
xColumn1.HeaderText = "X1"
Dim yColumn1 As New DataGridTextBoxColumn()
yColumn1.MappingName = "Y1"
yColumn1.HeaderText = "Y1"
Dim tableStyle As New DataGridTableStyle()
tableStyle.MappingName = "TeeDataTable"
Dim columnStyles As GridColumnStylesCollection
columnStyles = tableStyle.GridColumnStyles
columnStyles.Add(xColumn)
columnStyles.Add(yColumn)
columnStyles.Add(xColumn1)
columnStyles.Add(yColumn1)
dataGrid1.TableStyles.Add(tableStyle)
End Sub
Private Function GetData() As DataSet
Dim TeeDataSet As New DataSet()
Dim TeeDataTable As New DataTable("TeeDataTable")
Dim newRow As DataRow
Dim xval As New DataColumn("X", GetType(Double))
Dim yval As New DataColumn("Y", GetType(Double))
Dim xval1 As New DataColumn("X1", GetType(Double))
Dim yval1 As New DataColumn("Y1", GetType(Double))
TeeDataTable.Columns.Add(xval)
TeeDataTable.Columns.Add(yval)
TeeDataTable.Columns.Add(xval1)
TeeDataTable.Columns.Add(yval1)
For i As Integer = 0 To series1.Count - 1
newRow = TeeDataTable.NewRow()
newRow(xval) = series1.XValues(i)
newRow(yval) = series1.YValues(i)
newRow(xval1) = series2.XValues(i)
newRow(yval1) = series2.YValues(i)
TeeDataTable.Rows.Add(newRow)
Next
TeeDataSet.Tables.Add(TeeDataTable)
Return TeeDataSet
End Function
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
myForm.Show()
End Sub
I hope will helps.
Thanks,