user3516240
user3516240

Reputation: 375

Plotting Chart Data in Realtime Visual Basic

I'm working with a DevExpress Line Chart and I've ran into a small issue. The code below is part of my personal pinger application, I ping a lot of devices as part of my work duties to test the connection is online and of reasonable speed. I am trying to get the pings to visualize on a line chart, but each value I add to the chart using the code below doesn't connect up with the other.

However, if I take out the commented code series1.Points.Add(New SeriesPoint(15, 50)) all dots/data points connect up to that one on the chart... So I think its just not recognizing the other values to connect to because I'm adding them separately/real-time.

Is there a way I could just tell the chart to connect to its nearest argument value? So Ping 1 point connects to Ping 2 point with a line.

Do While PingCounter <= 10
            'Increment Ping Counter
            PingCounter = PingCounter + 1

            'Ping and return values
            Dim ping As Ping = New Ping()
            Dim pingreply As PingReply = ping.Send(txtHost.Text)
            ListBox1.Items.Add("Ping ID: " & PingCounter.ToString)
            ListBox1.Items.Add("Address: " & pingreply.Address.ToString() & Constants.vbCr)
            ListBox1.Items.Add("Roundtrip Time: " & pingreply.RoundtripTime & Constants.vbCr)
            ListBox1.Items.Add("TTL (Time To Live): " & pingreply.Options.Ttl & Constants.vbCr)
            ListBox1.Items.Add("Buffer Size: " & pingreply.Buffer.Length.ToString() & Constants.vbCr)

            'Declare integer for ping time
            Dim TripTime As Integer = pingreply.RoundtripTime

            'Clear chart1
            'Chart1.Series.Clear()

            'Update chart with ping ID and Ping Time
            Dim series1 As New DevExpress.XtraCharts.Series("Realtime Ping", ViewType.Line)
            series1.Points.Add(New SeriesPoint(PingCounter, TripTime))
            'series1.Points.Add(New SeriesPoint(15, 50))

            Chart1.CrosshairOptions.HighlightPoints = True
            Chart1.CrosshairOptions.ShowValueLine = True
            CType(series1.View, LineSeriesView).LineStyle.DashStyle = DashStyle.Solid

            ' Add the series to the chart.
            Chart1.Series.Add(series1)
            My.Application.DoEvents()
        Loop

This is just prototyle/proof of concept code and will obviously be significantly tidied up with a background worker.

Upvotes: 1

Views: 2776

Answers (1)

Jens
Jens

Reputation: 6375

You are adding each point as a different series to the chart. Declare and add a single series outside the loop, and just add points to it.

Dim series1 As New DevExpress.XtraCharts.Series("Realtime Ping", ViewType.Line)
Chart1.Series.Add(series1)
CType(series1.View, LineSeriesView).LineStyle.DashStyle = DashStyle.Solid
Chart1.CrosshairOptions.HighlightPoints = True
Chart1.CrosshairOptions.ShowValueLine = True
Do While PingCounter <= 10
    'Increment Ping Counter
    PingCounter = PingCounter + 1

    'Ping and return values
    Dim ping As Ping = New Ping()
    Dim pingreply As PingReply = ping.Send(txtHost.Text)
    ListBox1.Items.Add("Ping ID: " & PingCounter.ToString)
    ListBox1.Items.Add("Address: " & pingreply.Address.ToString() & Constants.vbCr)
    ListBox1.Items.Add("Roundtrip Time: " & pingreply.RoundtripTime & Constants.vbCr)
    ListBox1.Items.Add("TTL (Time To Live): " & pingreply.Options.Ttl & Constants.vbCr)
    ListBox1.Items.Add("Buffer Size: " & pingreply.Buffer.Length.ToString() & Constants.vbCr)

    'Declare integer for ping time
    Dim TripTime As Integer = pingreply.RoundtripTime


    'Update chart with ping ID and Ping Time

    series1.Points.Add(New SeriesPoint(PingCounter, TripTime))

    My.Application.DoEvents()
Loop

All points in one series are connected. Multiple series are used if you, for example, wanted to plot additional data in a different color in the same chart. So if, in your code, you uncommented the line you mentioned, each series contained two points (one point with always the same value) which are connected. What you want is all points in a single series.

Upvotes: 1

Related Questions