How DataSource Table filtering

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Nik
Newbie
Newbie
Posts: 9
Joined: Wed Mar 07, 2012 12:00 am

How DataSource Table filtering

Post by Nik » Sun Nov 11, 2012 7:49 pm

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.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How DataSource Table filtering

Post by Sandra » Mon Nov 12, 2012 3:49 pm

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply