Pada postingan kali ini saya akan share source code cara membuat grafik.Pada Visual Basic sendiri sebenarnya sudah punya kompoenen sendiri untuk menampilkan data dalam bentuk grafik, pada kali ini saya akan memakai komponen dari componentone yaitu ComponentOneChart v7. Jika belum punya komponenya silahkan downlod terlebuh dulu dan instal. jika tidak maka source codenya tidak akan bisa dijalankan sebaimana mestinya.
Berikut kode untuk pengaturan grafiknya, untuk contoh disini berupa grafik bar/batang :
Private Sub settingGrafik(ByVal Grafik As Chart2D, ByVal title As String, ByVal axesYTitle As String)
Grafik.Header.Text = title
' Change Footer Formatting
Grafik.Footer.Font.Size = 9
' Format the Y-axis to use Currency format
Grafik.ChartArea.Axes("Y").LabelFormat.Category = oc2dCategoryStandard
' Add Axes titles
Grafik.ChartArea.Axes("Y").title = axesYTitle
With Grafik.ChartArea
.Bar.ClusterWidth = 60 'lebar bar grafik
.Bar.ClusterOverlap = -100 'jarak antar bar grafik
End With
With Grafik.Header
.Font.Size = 10
.Font.Bold = True
End With
' Rotate the Y-Axis 90 degrees
Grafik.ChartArea.Axes("Y").TitleRotation = oc2dRotate90Degrees
' Add the legend to the chart
Grafik.Legend.IsShowing = True
Grafik.ChartGroups(1).ChartType = oc2dTypeBar 'jenis grafiknya diatur disini
End Sub
Selanjutnya tinggal kita tampilkan grafiknya :
Private Sub cmdPrevGrafik_Click() Dim numPoints As Long Dim numSeries As Long Dim iIndex As Long Dim iThn As Long Dim i As Long Dim jmlMhs As Long Grafik.Visible = False DoEvents With Grafik.ChartGroups(1).Data .numSeries = UBound(arrJurusan) + 1 'set jumlah jurusan .numPoints(1) = Val(cmbTahun2.Text) - Val(cmbTahun1.Text) + 1 numPoints = 0 iIndex = 0 Grafik.ChartLabels.RemoveAll For iThn = Val(cmbTahun1.Text) To Val(cmbTahun2.Text) numPoints = numPoints + 1 numSeries = 0 For i = LBound(arrJurusan) To UBound(arrJurusan) jmlMhs = getJumlahMhs(iThn, arrJurusan(i)) numSeries = numSeries + 1 .X(1, numPoints) = numPoints .Y(numSeries, numPoints) = jmlMhs Grafik.ChartLabels.Add iIndex = iIndex + 1 With Grafik.ChartLabels(iIndex) .AttachMethod = oc2dAttachDataIndex .AttachDataIndex.Series = numSeries .AttachDataIndex.Point = numPoints .Text = jmlMhs End With Next i Next iThn End With With Grafik.ChartGroups(1).SeriesLabels .RemoveAll Grafik.Legend.Text = "Jurusan" For i = LBound(arrJurusan) To UBound(arrJurusan) .Add arrJurusan(i) Next End With With Grafik.ChartGroups(1).PointLabels 'untuk menampilkan tahun Grafik.ChartArea.Axes("X").AnnotationMethod = oc2dAnnotatePointLabels .RemoveAll For i = Val(cmbTahun1.Text) To Val(cmbTahun2.Text) .Add i Next Grafik.ChartArea.Axes("X").title = "T a h u n" End With Grafik.Visible = TrueEnd SubJika anda tertarik silahkan Download komponennya dan source codenya. Semoga dapat bermanfaat
Sumber http://coding4ever.wordpress.com
Keyword:
Menampilkan Data Dalam Bentuk Grafik,Cara Membuat grafik,Cara Membuat Grafik Dengan VB 6,
Menampilkan Data Dengan Grafik di VB 6,Source code Cara Membuat Grafik,Source code Grafik dalam VB 6,
ComponentOneChart v7,Download ComponentOneChart v7,ComponentOneChart v7 Full,Key ComponentOneChart v7,
Serial Number ComponentOneChart v7,SN ComponentOneChart v7,Serial Key ComponentOneChart v7
No comments:
Post a Comment