Real Time FastLine/Line slow performance
Posted: Wed Jun 02, 2010 3:51 pm
Hi,
Environment: VS2008 / WPF / C#
Software: TeeChart WPF Ver. 3.5.3700.30575
It is better to explain what I need to do, so you will have a better idea what I am trying to accomplish here.
I have hardware sending data packets at 40 hertz. Each data packet contains 25 sample points. Now, I am interested in displaying 4(four) series in a chart in real time. If I connect 2 more hardware components (a total of 3 hardware components), I would end up with 3 graphs with 4 series each. The number of points we wish to display for each series is 10 000. So, worst case scenario I will need to display 3 graphs, with 4 series each, and each series containing the last 10 000 points. All of this real time.
I noticed that every time I update the graph the CPU percent usage skyrockets at 100%, and noticed there is huge delay in the data being displayed and the actual hardware readings. I am copying the code I use to display the graph.
I am encapsulating the Tchart component in another class. I tried using FastLine for better performance with no success.
Thanks,
RayDeveloper
Environment: VS2008 / WPF / C#
Software: TeeChart WPF Ver. 3.5.3700.30575
It is better to explain what I need to do, so you will have a better idea what I am trying to accomplish here.
I have hardware sending data packets at 40 hertz. Each data packet contains 25 sample points. Now, I am interested in displaying 4(four) series in a chart in real time. If I connect 2 more hardware components (a total of 3 hardware components), I would end up with 3 graphs with 4 series each. The number of points we wish to display for each series is 10 000. So, worst case scenario I will need to display 3 graphs, with 4 series each, and each series containing the last 10 000 points. All of this real time.
I noticed that every time I update the graph the CPU percent usage skyrockets at 100%, and noticed there is huge delay in the data being displayed and the actual hardware readings. I am copying the code I use to display the graph.
Code: Select all
public class KChart
{
public Dictionary<String, int> SeriesIndex = new Dictionary<string, int>();
/* Properties */
public TChart MainChart { get; set; }
/* Constructors */
public KChart() { this.MainChart = new TChart(); }
public KChart(string name, string bottomTitle, string leftTitle)
{
this.MainChart = new TChart();
this.MainChart.Header.Text = name;
this.MainChart.Aspect.View3D = false;
this.MainChart.Aspect.ZOffset = 0;
this.MainChart.TabIndex = 0;
this.MainChart.Panel.Bevel.Inner = BevelStyles.None;
this.MainChart.Panel.Bevel.Outer = BevelStyles.None;
this.MainChart.Panel.Gradient.Visible = false;
this.MainChart.Panel.Color = Color.FromArgb(0xff, 0xf5, 0xf5, 0xf5);
// Back wall
this.MainChart.Walls.Back.Gradient.Visible = false;
this.MainChart.Walls.Back.Color = Color.FromRgb(0x00, 0x00, 0x00);
// Axis
this.MainChart.Axes.Bottom.Title.Caption = bottomTitle;
this.MainChart.Axes.Left.Title.Caption = leftTitle;
this.MainChart.Axes.Left.AutomaticMaximum = true;
this.MainChart.Axes.Left.AutomaticMinimum = true;
this.MainChart.Axes.Left.Labels.ValueFormat = "0.0000000";
this.MainChart.Legend.Visible = true;
this.MainChart.Zoom.Allow = true;
this.MainChart.Zoom.Direction = Steema.TeeChart.WPF.ZoomDirections.Both;
// Install custom handlers
this.MainChart.Legend.LegendStyle = LegendStyles.Series;
//this.MainChart.GetLegendText += new GetLegendTextEventHandler(_GetLegendText);
}
/************************************* Custom Handlers **************************************************/
/*
private void _GetLegendText(object sender, GetLegendTextEventArgs e)
{
int index = e.Index;
var key = from k in this.SeriesIndex
where k.Value == index
select k.Key;
if(key!=null && index>=0)
e.Text = (string)key;
}
*/
/************************************* Custom Functions **************************************************/
public void DrawStyle(String seriesName, Series style, object xvalues, float[] yvalues)
{
if (!SeriesIndex.ContainsKey(seriesName))
{
SeriesIndex.Add(seriesName, SeriesIndex.Keys.Count);
style.Color = this.GenerateColor(SeriesIndex.Keys.Count);
if (style is Bar)
((Bar)style).Chart = this.MainChart.Chart;
else if (style is Line)
{
((Line)style).Chart = this.MainChart.Chart;
((Line)style).Pointer.Style = PointerStyles.Circle;
((Line)style).Pointer.Visible = true; ;
((Line)style).Title = seriesName;
Legend leg = new Legend(((Line)style).Chart);
LegendItem li = new LegendItem(leg);
((Line)style).Chart.Legend.Items.Add(li);
}
else if (style is FastLine)
{
((FastLine)style).Chart = this.MainChart.Chart;
((FastLine)style).Title = seriesName;
Legend leg = new Legend(((FastLine)style).Chart);
LegendItem li = new LegendItem(leg);
((FastLine)style).Chart.Legend.Items.Add(li);
}
}
if ((style is FastLine)||(style is Line))
{
//this.MainChart.Chart.AutoRepaint = false;
this.MainChart.Chart.Series[SeriesIndex[seriesName]].Clear();
if (xvalues != null)
{
if (xvalues is uint[])
this.MainChart.Chart.Series[SeriesIndex[seriesName]].Add((uint[])xvalues, yvalues);
else if (xvalues is float[])
this.MainChart.Chart.Series[SeriesIndex[seriesName]].Add((float[])xvalues, yvalues);
}
else
this.MainChart.Chart.Series[SeriesIndex[seriesName]].Add(yvalues);
//this.MainChart.Chart.AutoRepaint = true;
// try to see performance
this.MainChart.Chart.Series[SeriesIndex[seriesName]].RefreshSeries();
// Update the axis range
/*
if (this.MainChart.Chart.Series[SeriesIndex[seriesName]].MaxYValue()>0.0)
this.MainChart.Axes.Left.Maximum = this.MainChart.Chart.Series[SeriesIndex[seriesName]].MaxYValue() * 1.0001;
else
this.MainChart.Axes.Left.Maximum = this.MainChart.Chart.Series[SeriesIndex[seriesName]].MaxYValue() * 0.9999;
if (this.MainChart.Chart.Series[SeriesIndex[seriesName]].MinYValue()>0.0)
this.MainChart.Axes.Left.Minimum = this.MainChart.Chart.Series[SeriesIndex[seriesName]].MinYValue() * 0.9999;
else
this.MainChart.Axes.Left.Minimum = this.MainChart.Chart.Series[SeriesIndex[seriesName]].MinYValue() * 1.0001;
*/
}
}
}
Thanks,
RayDeveloper