Articles in this section
Category / Section

How do I filter particular set of data points in the WinForms Chart series?

3 mins read

Data is filtered on a series-by-series basis, and when a series data points are filtered they can be either removed from the series Points collection or marked as empty in WinForms Chart.
We can filter a particular set of data points using the Grouping Engine and data changes are reflected in chart.
Using the group engine we can set the main data source for the whole engine. The TableDescriptor will pick up the ItemProperties from the SourceList and table will be intialized at run-time with records from the list. Using RecordFilterDescriptor class we can filter the chart point values by comparing it against a given constant value. The filtered points added with series.
‚Äč
C#
// Generating Series
ChartSeries series =this.chartControl1 .Model.NewSeries ("Filter Series",ChartSeriesType.Column );
series.Text=series.Name;
list.Clear();
for(int i=0;i<10;i++)
{
a[i]=r.Next(300,500);
series.Points.Add(i,a[i]);
list.Add(new Data(i, a[i]));
}
this.chartControl1.Series.Add(series);
// Bind it to the model
Engine group=new Engine();
group.SetSourceList (list);
ExpressionFieldDescriptor exp = new ExpressionFieldDescriptor();
exp.Expression = "[Y] > "+this.textBox1.Text.ToString();
RecordFilterDescriptor rfd = new RecordFilterDescriptor(exp.Expression);
group.TableDescriptor.RecordFilters.Add (rfd);
System.Diagnostics.Trace.WriteLine("Filtered Record Count:" + group.Table.FilteredRecords.Count);
System.Diagnostics.Trace.WriteLine("Values greater than 30:");
// Filtering Data
this.chartControl1.Series[0].Points.Clear();
int j = 0;
foreach(Record rec in group.Table.FilteredRecords)
{
string b=rec.GetData().ToString();
System.Diagnostics.Trace.WriteLine(b);
this.chartControl1.Series[0].Points.Add(j,Convert.ToDouble(b));
j++;
}
this.label2.Text = "Number of Filtered points: "+group.Table.FilteredRecords.Count.ToString();
VB
' Generating Series
Dim series As ChartSeries =Me.chartControl1.Model.NewSeries ("Filter Series",ChartSeriesType.Column)
series.Text=series.Name
list.Clear()
For i As Integer = 0 To 9
a(i)=r.Next(300,500)
series.Points.Add(i,a(i))
list.Add(New Data(i, a(i)))
Next i
Me.chartControl1.Series.Add(series)
' Bind it to the model
Dim group As Engine = New Engine()
group.SetSourceList (list)
Dim exp As ExpressionFieldDescriptor = New ExpressionFieldDescriptor()
exp.Expression = "[Y] > " & Me.textBox1.Text.ToString()
Dim rfd As RecordFilterDescriptor = New RecordFilterDescriptor(exp.Expression)
group.TableDescriptor.RecordFilters.Add (rfd)
System.Diagnostics.Trace.WriteLine("Filtered Record Count:" & group.Table.FilteredRecords.Count)
System.Diagnostics.Trace.WriteLine("Values greater than 30:")
' Filtering Data
Me.chartControl1.Series(0).Points.Clear()
Dim j As Integer = 0
For Each rec As Record In group.Table.FilteredRecords
Dim b As String=rec.GetData().ToString()
System.Diagnostics.Trace.WriteLine(b)
Me.chartControl1.Series(0).Points.Add(j,Convert.ToDouble(b))
j += 1
Next rec
Me.label2.Text = "Number of Filtered points: " & group.Table.FilteredRecords.Count.ToString()


Conclusion

I hope you enjoyed learning about how to filter particular set of data points in the WinForms Chart series.

You can refer to our WinForms Charts feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Charts exampleto understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment