Andrzej Czerwoniec
Andrzej Czerwoniec

Reputation: 203

A few doubts about charts in C# .NET

I have a few question about charts in .NET in C#, I'm currently working on an app which will display data comming from serial port in real time.

I'm using a simple chart from .NET toolbox with spline series and there are two main feautures which I want to achieve.

The first one - I'd like the comming data points to be displayed on the right part of the chart and I'd like them to move to the left as the new data comes, I don't know how to describe it properly, I hope you can get the main idea since I can't post images yet.

I've achieved this kind of behaviour by reloading all the data points each time I refresh the chart, at first they are all empty and as the data comes I put the bigger and bigger queue of values in the end.

To clarify that the code may be like that:

chartAccelerationX.Series["XSeries"].Points.Clear();
dataPointTable = dataPointQueue.ToArray();
for (int i = 0; i < 1000; i++)
{
   DataPoint dataPointX = new DataPoint();

   if (1000 - dataPointTable.Length < i)
   {
      dataPointX.SetValueXY(i + 1, dataPointTable[i - 1000 + dataPointTable.Length].x);
    }
    else
    {
       dataPointX.IsEmpty = true;
    }
    chartAccelerationX.Series["XSeries"].Points.Add(dataPointX);
}
chartAccelerationX.Update();

It works pretty well, but as I said, I'm creating all the 1000 data points each time I update the chart (and I do it every 100ms) so it's probably disastrous in terms of performance (I'll need to have about 6-8 charts in total) and it's limited by the exact number od data points (1000 here).

Isn't there any easier way to achieve something like that with increasing amount of data points dynamically and with the second feature that I wanted to have - an auto matching scroll bar showing for example only 50 records at once?

I've been using a scrollbar as well, but it was just set to show 50 records out of 1000 and I could have scroll through all these empty data points right now. I can probably make the scrollbar appear after an exact number of data points are on the chart and update it every time the data is added but maybe theres any easier way?

I hope you understood what I was trying to say, I'm still working on my English.

Upvotes: 0

Views: 583

Answers (1)

Keith Nicholas
Keith Nicholas

Reputation: 44288

If you can use WPF, there is http://dynamicdatadisplay.codeplex.com/ and for the older WPF version http://dynamicdatadisplay.codeplex.com/wikipage?title=D3v1

which is pretty good, I've used it for some pretty high speed data sampling before

Upvotes: 1

Related Questions