0

I have a line chart, and with each new point added at the right, I want all the old line points to scroll one point position on the x-axis leftward, so that it appears to be sliding leftward.

I've used .AddXY to add all the points to fill the chart, and this works.

Me.Chart_window.Series( my_series ).Points.AddXY( x_axis_point, y_value)

But I can't figure out how to man

But I can't figure out how to manipulate the .Series.Points DataPointCollection to make the displayed line points appear to scroll leftward.

I tried .RemoteAt( 0 ) but this only deleted point at (0) without affecting displayed position of the other points.

I thought of copying all the existing points leftward one x-axis position before I append a new point, but I can't figure out how.

if CHART_IS_FILLING
    ' Graph not full of points yet, so new samples appear appending rightward.
    ' Show previous samples as same as before, and next samples appending:
    Me.Chart_antenna_window.ChartAreas("ChartArea1").AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount
    ' Plot next point:
            Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index).Points.AddXY( x_axis_point, antenna_amplitude_I)
        x_axis_point += 1

else      ' CHART IS FULL, SO START SLIDING LEFTWARD
    ' (Overaly graph is now full, so scroll it leftward by deleting leftmost sample before each new sample appended at right.)
    ' Scroll graph leftward:
    ' (ie. Remove left-point point, which is now beyond overlay window x-axis (ie. time) size):
    ' Shift all points leftward:
                Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index).Points.RemoveAt(0)


                ' HOW DO I SHIFT ALL THE POINTS LEFTWARD?    I can't see a way to read a point from DataPointCollection so that I can
                ' store it in the next index down.

        ' (All points shift left.)
    Me.Chart_antenna_window.ChartAreas("ChartArea1").AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount
    ' Plot next point at right-most chart point:
            Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index).Points.AddXY( x_axis_point, antenna_amplitude_I)
end if
Doug Null
  • 7,989
  • 15
  • 69
  • 148

2 Answers2

0

This is a complete guess as I haven't seen/used this charting thing but you'll have to loop over the collection of points after you remove the first, and decrement x by one to shift all the points leftwards:

ForEach p as Point in Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index).Points
  p.X -= 1
Next p

I don't know for sure what type of object is in the Points collection- hopefully it's called Point but you might have to adjust that (maybe it's a chartpoint or whatever). I'm also not well up on VB.Net these days, maybe there's a more short hand way of writing the foreach - in c# we don't always have to declare the type of variable if the compiler can work it out so foreach(var p in ...Points) would probably be fine in c#, maybe vb has an equivalent; VB.NET equivalent to C# var keyword might be helpful

You'd also do yourself a lot of favours if you declare a variable that refers to Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index) outside all your code:

Dim chart as Whatever = Me.Chart_antenna_window.Series( present_series_name & "_I" & graph_freq_index)

If blah Then
  chart.Points.AddXY ...
Else 
  chart.Points.AddXY ..

Any time you find yourself copying and pasting the same massive long line of code over and over, make a variable reference to it and use that to improve the readability of the code

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
0

I'd suggest Collection.RemoveAt(index) Method where index is the zero-based index of the element to remove, in your case 0