Monitoring grafik data secara real time memudahkan kita menganalisa pola data actual saat itu juga dengan mengacu pada visualisasi tampilan pola grafik data. Saat ini pengambilan dan pengolahan data secara real time atau actual sangat dibutuhkan dalam menganalisa, mengevaluasi dan memberikan solusi penanganan secara dini hasil kinerja dari suatu sistem. Contoh Windows Task Manager, pada jendela performance terdapat grafik CPU Usage History dan Physical Memory Usage History dari kedua grafik tersebut kita dapat mengetahui kinerja komputer secara real time.
Aplikasi yang saya buat ini merupakan sebuah gambaran bagaimana mekanisme menampilkan grafik data random secara real time, tentunya dari aplikasi ini dapat dilakukan pengembangan lebih lanjut untuk sistem lainnya bukan hanya diperuntukkan menampilkan data random saja.
Hasil tampilannya, perhatikan gambar paling atas. ToolBox yang akan kita gunakan, perhatikan table di bawah ini:
Desain Form dari ToolBox di atas perhatikan gambar di bawah ini.
Setelah Anda mendesain Form di atas dengan mengatur setiap properties yang di miliki oleh setiap object ToolBox. Ketikkan source program di bawah ini dengan mengarahkan kursor pada design Form, Klik kanan lalu pilih View Code.
Source Program:
'+++++++++++++++++++++++++++++++++++++++++++++++'
' 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 chunks 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, -NewValue)
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.EventArgs) Handles Timer1.Tick
PicGraph.Image = DisplayGuidelinesAndChart(PicGraph, Chunks, XMove, Me.count, minGraphs, maksGraph)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.Forms.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, FontStyle.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.EventArgs) 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.EventArgs) 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.EventArgs) Handles MyBase.Load
Label3.Text = "Number Data Random Record Pada Tabel : " & count1
End Sub
End Class
Setelah Anda mengetikkan listing source program diatas tekan F5, maka hasil tampilan visualnya seperti gambar di bawah ini, kemudian tekan tombol Start tampilannya seperti gambar paling atas.
Pengembangan Program dapat di sesuaikan dengan penggunaan yang diingikan, selamat Berkreasi.
Artikel terkait mengenai Tips ini:
DataGridView Auto Counter Visual Basic 2008 ===>>Klik disini
Grafik Dynamic Line Visual Basic 2008===>>Klik disini
ThreadGraph Dynamic Line Visual Basic 2008===>>Klik disini
Dynamic Line Plotting Data Random Visual Basic 2008===>>Klik disini
Selamat mencoba Guys! Nantikan Tips Aplikasi Cantik Lainnya by Verynandus Hutabalian
Aplikasi yang saya buat ini merupakan sebuah gambaran bagaimana mekanisme menampilkan grafik data random secara real time, tentunya dari aplikasi ini dapat dilakukan pengembangan lebih lanjut untuk sistem lainnya bukan hanya diperuntukkan menampilkan data random saja.
Hasil tampilannya, perhatikan gambar paling atas. ToolBox yang akan kita gunakan, perhatikan table di bawah ini:
Desain Form dari ToolBox di atas perhatikan gambar di bawah ini.
Setelah Anda mendesain Form di atas dengan mengatur setiap properties yang di miliki oleh setiap object ToolBox. Ketikkan source program di bawah ini dengan mengarahkan kursor pada design Form, Klik kanan lalu pilih View Code.
Source Program:
'+++++++++++++++++++++++++++++++++++++++++++++++'
' 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 chunks 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, -NewValue)
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.EventArgs) Handles Timer1.Tick
PicGraph.Image = DisplayGuidelinesAndChart(PicGraph, Chunks, XMove, Me.count, minGraphs, maksGraph)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.Forms.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, FontStyle.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.EventArgs) 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.EventArgs) 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.EventArgs) Handles MyBase.Load
Label3.Text = "Number Data Random Record Pada Tabel : " & count1
End Sub
End Class
Setelah Anda mengetikkan listing source program diatas tekan F5, maka hasil tampilan visualnya seperti gambar di bawah ini, kemudian tekan tombol Start tampilannya seperti gambar paling atas.
Pengembangan Program dapat di sesuaikan dengan penggunaan yang diingikan, selamat Berkreasi.
Artikel terkait mengenai Tips ini:
DataGridView Auto Counter Visual Basic 2008 ===>>Klik disini
Grafik Dynamic Line Visual Basic 2008===>>Klik disini
ThreadGraph Dynamic Line Visual Basic 2008===>>Klik disini
Dynamic Line Plotting Data Random Visual Basic 2008===>>Klik disini
Selamat mencoba Guys! Nantikan Tips Aplikasi Cantik Lainnya by Verynandus Hutabalian
0 komentar:
Posting Komentar