Sei sulla pagina 1di 3

'+++++++++++++++++++++++++++++++++++++++++++++++'

' Plotting Data Random Real Time '


'==============================================='
' Nilai Data random maksimum = 100 '
' Berbagi ilmu Sensasi Kepuasan Tersendiri '
' Created Programming by: Verynandus Hutabalian '
' Publish to V. Hutabalian's Blog 10 March 2010 '
'++++++++++++======================+++++++++++++'
Imports System.Drawing.Drawing2D
Public Class Form1
Private OldValue As Single = 0
Private NewValue As Single = 0
Dim XMove As Integer = 1
Dim Chunks As Integer = 12
Dim b As Integer
Dim count As Single
Dim maksGraph As Single = 120
Dim minGraphs As Single = 0
Dim count1 As Single
Dim intNumber As Integer
Private Function DisplayGuidelinesAndChart(ByVal PicBox As PictureBox, ByVal chu
nks As Integer, _
ByVal XMove As Integer, ByVal NewValue As Single, ByVal Min As Single, ByVal Max
As Single) As Bitmap
Dim bm As New Bitmap(PicBox.Width, PicBox.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
Dim MyPen As Pen = New Pen(Color.Blue, 3)
Dim MyPath As New GraphicsPath
Dim ValueRange As Single = Max - Min
Dim vScale As Single = PicBox.Height / ValueRange
gr.DrawPath(MyPen, MyPath)
Dim p As Pen = New Pen(Color.DarkRed, 2)
If Not IsNothing(PicBox.Image) Then
gr.DrawImage(PicBox.Image, -XMove, 0)
End If
NewValue *= vScale
gr.TranslateTransform(0, PicBox.Height)
If Min > 0 Then gr.TranslateTransform(0, Min * vScale)
gr.DrawLine(p, PicBox.Width - 10 - XMove, -OldValue, PicBox.Width - 10, -NewValu
e)
MyPath.AddEllipse(PicBox.Width - 10 - XMove, OldValue, 1, 1)
MyPath.AddRectangle(New Rectangle(PicBox.Width - 10, NewValue, 1, 1))
OldValue = NewValue
gr.RotateTransform(180)
gr.ScaleTransform(-1, 1)
gr.DrawPath(MyPen, MyPath)
gr.ResetTransform()
Return bm
gr.Dispose()
End Function

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventAr


gs) Handles Timer1.Tick
PicGraph.Image = DisplayGuidelinesAndChart(PicGraph, Chunks, XMove, Me.count, mi
nGraphs, maksGraph)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Event
Args) Handles Button1.Click
PicGraph.Refresh()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub PicGraph_Paint(ByVal sender As Object, ByVal e As System.Windows.For
ms.PaintEventArgs) Handles PicGraph.Paint
Dim ix As Integer = PicGraph.Width
Dim iy As Integer = PicGraph.Height
Dim chunks1 As Single = 12
Dim chunk As Single = ix / Chunks
Dim chunk1 As Single = iy / chunks1
Dim p As Pen = New Pen(Color.Gray, 0.05)
Dim MinValue As Single = PicGraph.Height
Dim MaxValue As Single = PicGraph.Height
Dim HowManyChunks As Single = 12
Dim chunk2 As Single = iy / HowManyChunks
For x As Integer = chunk To ix Step chunk
e.Graphics.DrawLine(p, x, 0, x, iy)
Next
For y As Integer = iy - chunk1 To 0 Step -chunk1
e.Graphics.DrawLine(p, 0, y, ix, y)
Next
Dim NextMarker As Integer = maksGraph
Dim ValueRange As Integer = maksGraph - minGraphs
For i As Single = 0 To iy Step chunk2
e.Graphics.DrawString(CStr(NextMarker), New Font("Verdana", 8, FontStyle.Regular
), Brushes.Yellow, 1, i)
NextMarker -= (ValueRange / HowManyChunks)
Next
e.Graphics.DrawString("VERYNANDUS HUTABALIAN", New Font("Lucida Handwriting", 10
, FontStyle.Regular), Brushes.Goldenrod, iy - 140, 6)
e.Graphics.DrawString("25 Maret 2009", New Font("Lucida Handwriting", 10, FontSt
yle.Regular), Brushes.Goldenrod, iy - 45, 20)
e.Graphics.DrawString("F I S I K A U N P A D", New Font("Lucida Handwriting", 10
, FontStyle.Regular), Brushes.Goldenrod, iy - 140, 40)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventAr
gs) Handles Timer2.Tick
Label1.Text = ""
Randomize()
intNumber = Int((100 * Rnd()) + 1)
Label1.Text = Label1.Text & intNumber
count = "" + Label1.Text

count1 = count1 + 1
Label3.Text = "Number Data Random Record Pada Tabel : " & count1
b = count1
DataGridView1.Rows.Add()
DataGridView1.Item(0, b - 1).Value = count1
DataGridView1.Item(1, b - 1).Value = Now
DataGridView1.Item(2, b - 1).Value = count
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Event
Args) Handles Button2.Click
PicGraph.Refresh()
PicGraph.Controls.Clear()
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArg
s) Handles MyBase.Load
Label3.Text = "Number Data Random Record Pada Tabel : " & count1
End Sub
End Class

Potrebbero piacerti anche