Upload
mohammadimron
View
6
Download
3
Embed Size (px)
DESCRIPTION
grafis dua dimensi
Citation preview
Selasa, 20 Oktober 2009
Grafik 2D PictureBox VB 2008Tips kali ini Grafik 2D menggunakan software Microsoft Visual Basic 2008 Express Edition.Perhatikan langkah-langkahnya sebagai berikut:
ToolBox yang digunakan perhatikan tabel di bawah ini:
STATUS NANDUS'S YM
Labels
33 Lirik Lagu Terpopuler Tanah Batak (1)Dunia Science Terkini (116)Jurnal Nasional UNILA SATEK II 2008 (1)Lirik Lagu (3)Salam Hangat Verynandus Hutabalian (1)Serba-Serbi Anak Kos (7)Tutorial Interface VB 2008 (42)Tutorial Triks dan Tips Excel 2007 (13)
Blog Archive
2011 (1) 2010 (42) 2009 (141)
Desember (31) November (47) Oktober (62)
Ledakan Meteor Bone Lampui Bom AtomLedakan Bone Adalah Asteroid JatuhMonster Laut Inggris vs T-RexNASA Sukses Uji Coba Prototipe Ares I-XGrafik Excel 2007 link V.Basic 2008Export DataGridView ke Excel 2007 VB 2008Visual Sinusoidal Visual Basic 2008Ida, Potongan Jejak Evolusi PrimataApakah Manusia Berevolusi?Anak SMP Pencipta Antivirus50 Perusahaan Kategori Hitam24 Pulau Indonesia HilangKemungkinan Asteroid Menabrak BumiTiga Peneliti Ribosom Raih Nobel KimiaNobel Fisika Diraih 3 Ilmuan ASThreadGraph Dynamic Line Visual Basic 2008Form Paint Visual Basic 2008Goa Terbesar di DuniaMenguak Misteri Si Raja LautUdang Tanpa MataPenemuan Terbaru Putra IndonesiaPecahan Keramik Abad XIIFosil Telur Dinosaurus IndiaFondasi Kuno 1.300 Tahun Lalu Ditemukan
HOME VISUAL BASIC 2008 EXCEL 2007 DUNIA SAINS CERITA ANAK KOSAN LIRIK LAGU BATAK DAFTAR ISI
V. HutabalianVisual Basic Interface
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
1 of 6 10/8/2013 10:15 PM
Perancangan/Design antar mukanya, perhatikan gambar di bawah ini:
Klik kanan pada Design, lalu pilih View Code isikan Source program seperti di bawah ini:
OptionStrictOn
Imports System.Drawing.Drawing2D
PublicClass Form1REM Data Grafik yang akan di plotDim Months() AsString = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", _ "Jul","Aug", "Sep", "Oct", "Nov", "Dec"}Dim Sales() AsInteger = {0, 314, 672, 429, 715, 642, 153, 699, 622, 901,345, 655}Dim LeftMargin AsInteger = 35 # of Pixels left unused at right side of PicBoxDim RightMargin AsInteger = 15 # of pixels above base of picturebox the X-Axis is placedDim BaseMargin AsInteger = 35 Margin at TopDim TopMargin AsInteger = 10 Variable to hold length of vertical axisDim VertLineLength AsInteger Variable to hold length of horizontal axisDim BaseLineLength AsInteger Variable to store length of each line segmentDim LineWidth AsDouble
Manusia Purba Gunung KidulJejak Dinosaurus TerbesarFosil Gading Gajah Purba Sembarangan"Ardi" Nenek Moyang Pertama ManusiaFosil Gajah Purba TeridentifikasiCumi-cumi Raksasa T. MeksikoTuak Sebagai Energi AlternatifPlanet Terbaru Mengandung Molekul Organik32 Planet TerbaruAsteroid Terbesar Kedua BimasaktiMiliarder Kanada Kembali dari Luar AngkasaCincin terbesar Planet SaturnusGraphic Dynamic Line VB 2008Pie Chart Visual Basic 2008Bar 2D Visual Basic 2008Bar 3D Visual Basic 20083D Shape VB 2008Proteksi Folder ManualGrafik 2D PictureBox VB 2008Proteksi Folder dengan Notepad Ekstensi .batDataGridView Outo Rows CounterTimer Auto Shut Down PCJam Digital Visual Basic 2008Menyimpan file di Recent DocumentBurung Pertama Bukan BurungRobot PelompatUntaian Genom dalam 3DProteksi FormulaProteksi sel33 Lirik Lagu Terpopuler Tanah BatakProtect File ExcelProteksi Lembar kerja SheetTransfer Data Antar Sheet ExcelAFGAN "SBertahan Rio FerbrianSOFTWARE VISUAL BASIC RAY TRACERGrafik Dinamis Microsoft Excel 2007Shine lyrics
September (1)
About Me
Verynandus HutabalianBerbagi hal sedikit dari hal-hal berharga yangaku miliki. Chayooo!!!Lihat profil lengkapku
49.466Yang Nimbrung COY!!!
ShoutMixLive chat softwarefor your website
Click here to check itout now!
0.001s
ShoutMix chat widget
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
2 of 6 10/8/2013 10:15 PM
Dim g As Graphics Next, create a Bitmap object which is the same size and resolution as the PictureBoxDim bmap As Bitmap
PrivateSub DrawOutline()bmap = New Bitmap(PBLineChart.Width, PBLineChart.Height,PBLineChart.CreateGraphics) Assign the Bitmap to the Graphics object.g = Graphics.FromImage(bmap)Dim StartPoint AsNew Point(LeftMargin, PBLineChart.Height - BaseMargin)Dim EndPoint AsNew Point(LeftMargin, TopMargin) Basic Pen to draw outline linesDim LinePen AsNew Pen(Color.Red, 2) Draw the vertical lineg.DrawLine(LinePen, StartPoint, EndPoint)Dim VertLineLength AsInteger = PBLineChart.Height - (BaseMargin +TopMargin)Dim VertGap AsInteger = CInt(VertLineLength / 10)Dim TickSP AsNew Point(LeftMargin - 5, StartPoint.Y - VertGap)Dim TickEP AsNew Point(LeftMargin, StartPoint.Y - VertGap)Dim ValueFont AsNew Font("Arial", 8, FontStyle.Regular)For i AsInteger = 1 To 10 Tick markg.DrawLine(New Pen(Color.Black), TickSP, TickEP) Tick Values as textg.DrawString(CStr(i * 100), ValueFont, Brushes.Red, 2, TickSP.Y - 5) Reset y positions, moving 10% up vertical lineTickSP.Y -= VertGapTickEP.Y -= VertGapNextg.DrawLine(LinePen, LeftMargin, PBLineChart.Height - BaseMargin,PBLineChart.Width - RightMargin, PBLineChart.Height - BaseMargin)EndSub
PrivateSub btnDraw_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnDraw.ClickDrawOutline()DrawHorizontalLines()DrawVerticalGridLines()DrawTheLine()ShowMonths()FinalDisplay()EndSub
PrivateSub DrawTheLine()Dim MyPath AsNew GraphicsPathDim MyPen As Pen = New Pen(Color.Blue, 3)g.DrawPath(MyPen, MyPath)Dim VertScale AsDoubleDim VertLineLength AsInteger = PBLineChart.Height - (BaseMargin +TopMargin)Dim MyPath As New GraphicsPathDim XPosStart AsInteger = CInt(LeftMargin + 30)VertScale = VertLineLength / 1000Dim XPosEnd AsInteger = CInt(XPosStart + LineWidth)Dim YPosStart AsInteger = CInt(Sales(0) * VertScale)Dim YPosEnd AsInteger = CInt(Sales(1) * VertScale)Dim MyPath As New GraphicsPath Manually add the first circle to the pathMyPath.AddEllipse(XPosStart - 2, YPosStart - 2, 4, 4) Manually add the first line to the PathMyPath.AddLine(XPosStart, YPosStart, XPosEnd, YPosEnd)MyPath.AddRectangle(New Rectangle(XPosEnd - 2, YPosEnd - 2, 4, 4))For i AsInteger = 1 To UBound(Sales) - 1 Update the X and Y positions for the next value: Move start point one line width to the rightXPosStart = XPosEnd
My blog is worth$564.54.
How much is your blogworth?
Live Traffic Feed
A visitor from Surabaya, JawaTimur viewed "V. Hutabalian:MSChart vs Visual Basic 2008Express Edition" 17 mins agoA visitor from Surabaya, JawaTimur viewed "V. Hutabalian:Export DataGridView ke Excel2007 VB 2008" 6 hours 30mins agoA visitor from Indonesiaviewed "V. Hutabalian: GrafikDinamis Microsoft Excel 2007"7 hours 47 mins agoA visitor from Jakarta, JakartaRaya viewed "V. Hutabalian:Grafik Dinamis MicrosoftExcel 2007" 8 hours 7 mins agoA visitor from Ottawa, Ontarioviewed "V. Hutabalian: 50Perusahaan Kategori Hitam" 10hours 5 mins agoA visitor from Indonesiaviewed "V. Hutabalian: GrafikDinamis Microsoft Excel 2007"11 hours 20 mins agoA visitor from Bandung, JawaBarat viewed "V. Hutabalian:Batu Megalitikum Usia RibuanTahun" 11 hours 48 mins agoA visitor from Indonesiaviewed "V. Hutabalian: GrafikDinamis Microsoft Excel 2007"12 hours 17 mins agoA visitor from Jakarta, JakartaRaya viewed "V. Hutabalian:ThreadGraph Dynamic LineVisual Basic 2008" 15 hours 54
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
3 of 6 10/8/2013 10:15 PM
Move end point one line width to the rightXPosEnd = CInt(XPosStart + LineWidth) Assign YPosStart the old value of YYPosStart = YPosEnd Assign YPosEnd the next the next scaled Sales figureYPosEnd = CInt(Sales(i + 1) * VertScale) Add next circleMyPath.AddEllipse(XPosStart - 2, YPosStart - 2, 4, 4) Add the next line segment to the GraphicsPathMyPath.AddLine(XPosStart, YPosStart, XPosEnd, YPosEnd)Next Finally, manually add the last circleMyPath.AddEllipse(XPosEnd - 2, YPosEnd - 2, 4, 4)g.RotateTransform(180) Because the rotation also moves the line out of view (to the left), so we need to scale the x so that it is on the (plus) side of the vertical axis. The Y value remains unchanged, so a "scale" of 1 is used. (i.e. no change made)g.ScaleTransform(-1, 1) Move the start point down to the bottom left corner The X value remains the same Y is shifted down to the end of the vertical axis, adjusted by a fudge factor of 10 to compensate for the vertical scaling.g.TranslateTransform(0, VertLineLength + 10, MatrixOrder.Append)Dim MyPen As Pen = New Pen(Color.Blue, 3)g.DrawPath(MyPen, MyPath)g.ResetTransform()EndSub
PrivateSub FinalDisplay()PBLineChart.Image = bmapg.Dispose()EndSub
PrivateSub ShowMonths() Set the start point of the first stringDim TextStartX AsInteger = CInt(LeftMargin + 18) Create a Brush to draw the textDim TextBrsh As Brush = New SolidBrush(Color.Red) Create a Font object instance for text displayDim TextFont AsNew Font("Arial", 10, FontStyle.Regular)For i AsInteger = 0 To Months.Length - 1 Draw the name of the onthg.DrawString(Months(i), TextFont, TextBrsh, TextStartX, _CInt(PBLineChart.Height - (BaseMargin - 4))) Move start point for next name along to the rightTextStartX += CInt(LineWidth)NextEndSub
PrivateSub DrawVerticalGridLines()Dim ThinPen AsNew Pen(Color.LightGreen, 2)Dim StartPoint As New Point(LeftMargin, PBLineChart.Height - BaseMargin)Dim EndPoint As New Point(LeftMargin, TopMargin)Dim StartPoint AsNew Point(LeftMargin, PBLineChart.Height - BaseMargin)Dim EndPoint AsNew Point(LeftMargin, TopMargin)Dim Sales() As Integer = {835, 314, 672, 429, 715, 642, 153, 699, 622,901, 345, 655} Basic Pen to draw outline linesDim LinePen AsNew Pen(Color.Red, 2) Draw the vertical lineg.DrawLine(LinePen, StartPoint, EndPoint) Calculate length of baseline drawn by the code aboveBaseLineLength = PBLineChart.Width - (LeftMargin + RightMargin) Calculate the width of each line segmentLineWidth = (BaseLineLength / Sales.Length) Set the start point of the first string
Ads Powered
by:KumpulBlogger.com
Pilih BahasaDiberdayakan oleh Terjemahan
Blogger Templates by Verynandus Hutabalian Dot Com andSupported by Tutorial VB 2008.Com - V. Hutabalian's Blog
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
4 of 6 10/8/2013 10:15 PM
Dim LineStartX AsInteger = CInt(LeftMargin + 30)For i AsInteger = 0 To Months.Length - 1g.DrawLine(ThinPen, LineStartX, TopMargin, LineStartX, PBLineChart.Height -(BaseMargin + 4)) Move start point along to the rightLineStartX += CInt(LineWidth)NextThinPen.Dispose()EndSub
PrivateSub DrawHorizontalLines() Calculate vertically equal gapsDim VertLineLength AsInteger = PBLineChart.Height - (BaseMargin +TopMargin)Dim VertGap AsInteger = CInt(VertLineLength / 10) Set the Start and End points = Left and right margins on the baselineDim StartPoint AsNew Point(LeftMargin + 3, PBLineChart.Height - BaseMargin)Dim EndPoint AsNew Point(PBLineChart.Width, PBLineChart.Height -BaseMargin) Initial settingsDim LineStart AsNew Point(StartPoint.X, StartPoint.Y - VertGap)Dim LineEnd AsNew Point(EndPoint.X, StartPoint.Y - VertGap)Dim ThinPen AsNew Pen(Color.LightGreen, 3)For i AsInteger = 1 To 10 Draw a lineg.DrawLine(ThinPen, LineStart, LineEnd) Reset Start and End Y positions, moving up the vertical lineLineStart.Y -= VertGapLineEnd.Y -= VertGapNextThinPen.Dispose()EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ClickEndEndSub
EndClass
Dengan menekan F5 maka tampilannya seperti gambar di bawah ini:
Untuk menampilkan Grafiknya tekan tombol Tampilkan (gambar pertama di atas) dan untukmenutup tekan Tutup.
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
5 of 6 10/8/2013 10:15 PM
Posting Lebih Baru Posting Lama
Selamat mencoba Guys! Nantikan Tips Aplikasi Cantik Lainnya by Verynandus Hutabalian
Label: Tutorial Interface VB 2008
Diposkan oleh Verynandus Hutabalian di 06.44
0 komentar:
Poskan Komentar
Link ke posting ini
Buat sebuah Link
Beranda
Langganan: Poskan Komentar (Atom)
Tutorial Visual Basic 2008
1. Jam Digital Visual Basic 2008 2. Timer Auto Shut Down Visual Basic 2008 3. DataGridView Auto Counter Visual Basic 2008 4. 3D Shape Visual Basic 2008 5. Bar 3D Visual Basic 2008 6. Bar 2D Visual Basic 2008 7. Pie Chart Visual Basic 2008 8. Graphic Dynamic Line Visual Basic 2008 9. Graphic 2D PictureBox10. Dynamic Line Visual Basic 200811. Graphic Form Paint Visual Basic 200812. Visual Sinusoidal Visual Basic 200813. Export DataGridView Ke Excel 2007 Visual Basic 2008
Dunia Science Terkini
1. Untaian Genom Dalam 3D 2. Robot Pelompat 3. Burung Pertama Bukan Burung 4. Cincin Terbesar Planet Saturnus 5. Miliarder Kanada Kembali Dari Luar Angkas 6. Asteroid Terbesar Kedua di Bimasakti 7. 32 Planet Terbaru 8. Planet Terbaru Mengandung Molekul Organik 9. Tuak Sebagai Energi Alternatif10. Cumi-Cumi Raksasa Teluk Meksiko11. Fosil Gajah Purba Teridentifikasi12. "Ardi" Nenek Moyang Pertama Manusia13. Konserfasi Gading Gajah Purba Sembarangan
Tutorial Triks & Tips Excel 2007
1. Grafik Dinamis Microsoft Excel 2007 2. Transfer Data Antar Sheet Excel 3. Proteksi Lembar Kerja Sheet 4. Proteksi File Excel 2007 5. Proteksi Sel Excel 2007 6. Proteksi Formula Excel 2007 7. Menyimpan File Recent Document 8. Proteksi Folder dengan Notepad Ekstensi.bat 9. Proteksi Folder Manual 10. Dua Data Dalam Satu Grafik Pie 11. Visual Data Grafik Excel 2007 vs VBA 12. Grafik Excel 2007 to Visual Basic Application
Copyright September 2009 | Berbagi Tutorial | Berbagi Visual Basic 2008 | Dunia Science
Blog by: V. Hutabalian Tips & Triks
V. Hutabalian: Grafik 2D PictureBox VB 2008 http://verynandushutabaliansblog.blogspot.com/2009/10/grafik-2d-pictur...
6 of 6 10/8/2013 10:15 PM