Page 1 of 1
How DataSource Table filtering
Posted: Sun Nov 11, 2012 7:49 pm
by 15661911
Hi,
How DataSource Table filtering
Example
Code: Select all
dataset1.Tables["MyTable"].DefaultView.RowFilter = string.Format("{0}", "Field1 = 'filterPattern'");
serie.DataSource = dataset1.Tables["MyTable"];
serie.YValues.DataMember = "Field1";
serie.XValues.DataMember = "Field1";
This example don't work.
Re: How DataSource Table filtering
Posted: Mon Nov 12, 2012 3:49 pm
by 10050769
Hello Nik,
If you want to work with a DataTable filtering with TeeChart, you need create a new DataTable where there is a filter that you must make previously. I suggest you use next code and taking a look in GetFilter() method, where you can see how you make a filter correctly.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Styles.Line series;
private void InitializeChart()
{
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
series = new Line(tChart1.Chart);
//GetFilter of DataSet
series.DataSource = GetFilter(GetData());
series.XValues.DataMember = "X";
series.YValues.DataMember = "X";
tChart1.DoubleClick += new EventHandler(tChart1_DoubleClick);
}
private DataSet GetData()
{
DataSet TeeDataSet = new DataSet();
DataTable TeeDataTable = new DataTable("DataTable");
DataColumn xval = new DataColumn("X", typeof(double));
DataColumn yval = new DataColumn("Y", typeof(double));
TeeDataTable.Columns.Add(xval);
TeeDataTable.Columns.Add(yval);
for (int i = 0; i < 10; i++)
{
DataRow newRow = TeeDataTable.NewRow();
newRow[xval] = i;
newRow[yval] = i+1;
TeeDataTable.Rows.Add(newRow);
}
TeeDataSet.Tables.Add(TeeDataTable);
return TeeDataSet;
}
private DataTable GetFilter(DataSet TeeDataSet)
{
DataTable DataTableFilter = new DataTable("Filter");
//Condition to filter
DataRow[] foundRow = GetData().Tables["DataTable"].Select("Y>4");
//AddColumns in new Table
DataColumn xval = new DataColumn("X", typeof(double));
DataColumn yval = new DataColumn("Y", typeof(double));
DataTableFilter.Columns.Add(xval);
DataTableFilter.Columns.Add(yval);
for (int i = 0; i < foundRow.Length; i++)
{
DataRow newRow = DataTableFilter.NewRow();
newRow[xval] = foundRow[i][0];
newRow[yval] = foundRow[i][1];
DataTableFilter.Rows.Add(newRow);
}
return DataTableFilter;
}
void tChart1_DoubleClick(object sender, EventArgs e)
{
tChart1.ShowEditor();
}
Could you please, tell us if previous code works in your end?
I hope will helps.
Thanks,