|
-
Dec 2nd, 2011, 04:55 PM
#10
Thread Starter
Lively Member
Re: Zedgraph Real Time
right, i've got a good little real time graph which is just being updated by a timer event putting a sine wave onto the graph. i've set up a boolean to control when I start to scroll back in time, which stops updating the graph, but still updates the list, so when i double click the graph, it starts back up again. the only niggle i have with this is that when i scroll back in time, i can't scroll forwards because the scroll bar grows and doesn't let me.
here's my code, but thanks for the tips, as you can see, i can't seem to get the graph going without using the 'creategraph' sub. i tried doing it on form load, and then only using the refresh and axischange, but to no avail.?
even if this as far as i can go i still really like Zedgraph!
vb Code:
Imports ZedGraph
Public Class Form1
Private inhibit_scroll As Boolean = False
Private x As Double = 0.0, y As Double = 0.0
Private alist = New PointPairList()
Private zgc = New ZedGraphControl
Dim maxX As Double = 9.0, maxY As Double = 8000.0, minX As Double = 0.0, minY As Double = 0.0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' CreateGraph(zgc)
End Sub
Private Sub CreateGraph(ByVal zgc As ZedGraphControl)
Dim myPane As GraphPane = zgc.GraphPane
myPane.XAxis.Scale.Max = maxX
myPane.XAxis.Scale.Min = minX
myPane.YAxis.Scale.Max = maxY
myPane.YAxis.Scale.Min = minY
' Set the titles and axis labels
myPane.Title.Text = "Flow Meter A"
myPane.XAxis.Title.Text = "Time"
myPane.YAxis.Title.Text = "Kg/Hr"
myPane.CurveList.Clear()
' Generate a blue curve
Dim myCurve As LineItem = myPane.AddCurve("Flow Meter A", alist, Color.Red, SymbolType.None)
myPane.Chart.Fill = New Fill(Color.Black, Color.Gray)
' Calculate the Axis Scale Ranges
zgc.AxisChange()
'zgc.Invalidate()
zg1.Refresh()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = x
Label2.Text = maxX
x = x + 0.1
y = (3800 * Math.Sin(0.5 * x)) + 4000
alist.add(x, y)
' zgc = New ZedGraphControl
If Not inhibit_scroll Then
CreateGraph(zg1)
End If
' if the graph has reached the end of the trace, then start to advance the axis.
If x > maxX Then
minX = minX + 0.1
maxX = maxX + 0.1
End If
End Sub
Private Sub zg1_ScrollProgressEvent(ByVal sender As ZedGraph.ZedGraphControl, ByVal scrollBar As System.Windows.Forms.ScrollBar, ByVal oldState As ZedGraph.ZoomState, ByVal newState As ZedGraph.ZoomState) Handles zg1.ScrollProgressEvent
inhibit_scroll = True
End Sub
Private Sub zg1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zg1.DoubleClick
inhibit_scroll = False
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|