Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a chart in my application, in which, the points are like time and a value pair.
Time On X-axis, and value on y-axis. and for each second or 100 mille seconds a new point will be added to the chart.

Here the problem is when a new point added, the graph points gets closer, but i want to move or scroll the older points to the left of the chart.

I am adding my code snippets here..


VB
Private Sub Graph_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        XVal = DateTime.Now
        YVal = rnd.Next(50, 100)
        With Chart1.Series(0)
            .Name = "Sample"
            .ChartType = SeriesChartType.Spline
            .Color = Color.Black
            .IsValueShownAsLabel = False
            .IsXValueIndexed = False
            .Points.AddXY(XVal, YVal)
        End With
        With Chart1.ChartAreas(0)
            .AxisX.IntervalType = DateTimeIntervalType.Minutes
            .AxisX.Interval = 1
            .AxisY.Interval = 10
            .AxisX.LabelStyle.Angle = -90
            .AxisX.Title = "TimeStamp"
            .AxisY.Title = "Units"
            .CursorX.IsUserEnabled = True
            .CursorX.IsUserSelectionEnabled = True
            .CursorX.IntervalType = DateTimeIntervalType.Minutes
            .CursorX.Interval = 0.5D


            .AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Minutes
            .AxisX.ScaleView.SmallScrollSize = 0.5D
            .AxisX.ScaleView.Zoomable = True
            .AxisX.LabelStyle.Format = "hh:mm:ss"
            .AxisX.ScrollBar.Enabled = True
                    End With
    End Sub


VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.tick
        Chart1.Series(0).Points.AddXY(DateTime.Now, rnd.Next(50, 100)
    End Sub




I need help on this ASAP, any help will be greatful
Posted
Updated 29-Nov-18 4:32am
v2

1 solution

I realise it has been 5 years since OP posted, but in case someone else stumbles upon this post with the same problem.

This is an example of what I used in one of my projects:
Chart1.Series("LoadCell").Points.AddY(receivedData)
Chart1.ResetAutoValues()

If Chart1.Series("LoadCell").Points.Count >= 100 Then
     Chart1.Series("LoadCell").Points.RemoveAt(0)
End If

It Auto scales the y axis as well as limiting the x axis to 100 by removing the first entry when the entries exeed 100.

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900