Untuk Membuat Grafik Mschart dengan Visual basic 6 ini saya menggunakan metode grafik data Non-Database. Silahkan kan simak langkah-langkah tahapannya :
1. Pertama – tama pastikan dahulu Komponen grafik sudah muncul pada Toolbar visual basic.
3. Kemudian akan muncul Components Dialog, check Microsoft Chart Control 6.0 dan klik OK.
Dan jangan lupa
pada visual basic menambah kan Setting References "Microsoft Activex
Data Objeck 2.0 Library" seperti gambar di bawah
Kompoenen Microsoft Activex Data Objeck 2.0 Library |
4. Buatlah desain Form dan setting propertiesnya seperti di bawah ini
Berikut ini adalah code VB yang digunakan:
Letakan pada Form load
Private Sub Form_Load() 'List Combo: chart types With Combo1 .AddItem "3D Bar" .AddItem "2D Bar" .AddItem "3D Line" .AddItem "2D LIne" .AddItem "3D Area" .AddItem "2D Area" .AddItem "3D Step" .AddItem "2D Step" .AddItem "3D Combination" .AddItem "2D Combination" .ListIndex = 1 'default:2D Bar End With Check1.Caption = "&Show Legends"
'2D array --> chart values Dim X(1 To 7, 1 To 6) As Variant X(1, 2) = "Jakarta" X(1, 3) = "Bandung" X(1, 4) = "Cirebon" X(1, 5) = "Bogor" X(1, 6) = "Sukabumi"
X(2, 1) = "JAN" X(2, 2) = 3 X(2, 3) = 4 X(2, 4) = 5 X(2, 5) = 6 X(2, 6) = 7
X(3, 1) = "FEB" X(3, 2) = 4 X(3, 3) = 5 X(3, 4) = 3 X(3, 5) = 8 X(3, 6) = 12
X(4, 1) = "MAR" X(4, 2) = 1 X(4, 3) = 3 X(4, 4) = 8 X(4, 5) = 10 X(4, 6) = 9
X(5, 1) = "APR" X(5, 2) = 4 X(5, 3) = 6 X(5, 4) = 12 X(5, 5) = 10 X(5, 6) = 14
X(6, 1) = "MAY" X(6, 2) = 2 X(6, 3) = 9 X(6, 4) = 7 X(6, 5) = 12 X(6, 6) = 8
X(7, 1) = "JUN" X(7, 2) = 12 X(7, 3) = 19 X(7, 4) = 5 X(7, 5) = 19 X(7, 6) = 10 '2D array --> chart data MSChart1.ChartData = X End Sub
Letakan pada Checkbox
Private Sub Check1_Click() If Check1.Value = 1 Then 'Show Legends MSChart1.ShowLegend = True Check1.Caption = "&Hide Legends" Else 'Hide Legends MSChart1.ShowLegend = False Check1.Caption = "&Show Legends" End If End SubLetakan pada Combo
Private Sub Combo1_Click() 'chart type -->run time. MSChart1.chartType = Combo1.ListIndex End Sub