In WinForms, I'm trying to create an interactive chart but am having difficulties with one aspect. I am using System.Windows.Forms.DataVisualization.Charting.Chart for the chart, and using a FastLine series to render the data.
In this chart, you can zoom/pan/change channels, and new points are dynamically added / removed as needed. The reason for this is that the source of these points is a large binary file that can be well over a gigabyte, and I am using a MemoryMappedFile to pull as little data as possible to increase performance.
When panning to the right, everything works fine - new points are added to the end of the list and you can't even tell that they were not there a second ago.
However, when I pan to the left, the graph displays in a very odd way. There are lines running all over the place. I know what is happening here, I just can't figure out how to fix it.
The cause is that when a point is added, a line is drawn from the last point added to the new one. So if the last point was added to the right side, and the new point is added to the left side, a line will shoot across the graph.
Here is the code that adds points to the graph:
for (var i = scanStart; i + _step <= scanEnd; i += _step)
{
var sample = _expeData.ReadSample(channel, i);
Series[0].Points.AddXY(i, sample);
}
Is there any way to prevent this from happening? Here is a screenshot showing what it looks like after panning to the left: