Sekitar 1 bulan lalu saya diminta oleh seorang sahabat untuk mengajari beliau cara membuat Chart di VB 2010. Karena waktu beliau juga sangat padat akhirnya saya buatkan coding yang disesuaikan dengan kebutuhan beliau sebagai contoh untuk pelajari.
Berikut ini saya share codingnya, semoga bermanfaat.
Imports System.Windows.Forms.DataVisualization.Charting
Public Class frmExample6
Private dtTest As New DataTable
Private Sub cmdProses_Click(sender As System.Object, e As System.EventArgs) Handles cmdProses.Click
Dim i As Integer
Dim j As Integer
Dim jumlahData As Integer
jumlahData = 1 + ((Val(Me.txtMaximum.Text) - Val(Me.txtMinimum.Text)) / Val(txtSelang.Text))
Dim aLi(jumlahData) As Double
Dim aWi(jumlahData) As Double
Dim arrData(jumlahData, jumlahData) As Double
aLi(0) = Val(Me.txtMinimum.Text)
aWi(0) = Val(Me.txtA.Text) * aLi(0) ^ Val(Me.txtB.Text)
For i = 1 To jumlahData - 1
aLi(i) = aLi(i - 1) + Val(Me.txtSelang.Text)
aWi(i) = Val(Me.txtA.Text) * aLi(i) ^ Val(Me.txtB.Text)
Next
dtTest.Columns.Add("aLi", GetType(Double))
dtTest.Columns.Add("aWi", GetType(Double))
For i = 0 To jumlahData - 1
dtTest.Rows.Add(aLi(i), aWi(i))
Next
DataGridView1.DataSource = dtTest.DefaultView
DataGridView1.Columns(0).Width = 50
End Sub
Private Sub cmdChart_Click(sender As System.Object, e As System.EventArgs) Handles cmdChart.Click
Chart1.Dock = DockStyle.Bottom
Chart1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Top
'Chart1.Series.Add("aWi")
With Chart1.Series(0)
' .Name = "aLi"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = False
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "aLi", "aWi", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 15"
.ChartType = SeriesChartType.Line
End With
End Sub
End Class
Monday, November 4, 2013
Membuat Chart di VB 2010
6:16 AM
Ridwan