If there are some data of Products, and OrderDetails.

Products

OrderDetails

If you needed to try this sample application, just create those table in your database.

Products

ProductId Number, ProductName Text(40)

OrderDetails

ProductId Number, TotalQuantity Number

Arrange products quantity chart that consist of data from those tables!

First of all, you need to join the table to get productid and productname from Products, and then totalquantity from OrderDetails. Here is the query:

Select a.productid,a.productname,sum(b.totalquantity) as totalquantity

From products as a inner join orderdetails as b

on a.productid = b.productid

Group by a.productid,a.productname

Order by a.productid

Here is the result of query execution:

If you want to make an application that contains chart in it, create a project in Microsoft Visual Basic 6.0, add Microsoft Chart Control 6.0 to your project, and drag drop the component into your form.

Create this code to your form:

Dim Cn As ADODB.Connection

Dim Rs As ADODB.Recordset

Private Sub Form_Load()

Set Cn = New ADODB.Connection

Cn.ConnectionTimeout = 30

Cn.CommandTimeout = 0

Cn.ConnectionString = “Provider=Microsoft.Jet.Oledb.4.0;” & _

“Data Source=” & App.Path & “\Northwind.mdb;” & _

“Jet Oledb:Database password=”;”

Cn.CursorLocation = adUseClient

Cn.Open

Set Rs = New ADODB.Recordset

Rs.Open “Select a.productid,a.productname,sum(b.totalquantity) As

totalquantity From products as a inner join orderdetails as b on

a.productid = b.productid Group by a.productid,a.productname Order by

a.productid”, Cn

If Not Rs.EOF Then

MSChart1.ColumnCount = 1

MSChart1.ColumnLabel = “Product Name”

MSChart1.RowCount = Rs.RecordCount

MSChart1.Column = 1

Dim i As Integer

i = 1

Do While Not Rs.EOF

MSChart1.Row = i

MSChart1.RowLabel = Rs(”productname”)

MSChart1.Data = Rs(”totalquantity”)

i = i + 1

Rs.MoveNext

Loop

End If

Rs.Close

Set Rs = Nothing

If Not Cn Is Nothing Then

Cn.Close

Set Cn = Nothing

End If

End Sub

Here is the result of chart:

4 Responses to “How To Make a Chart in Ms Visual Basic 6.0”

  1.   private jets | Digg hot tags said:

    [...] Vote How To Make a Chart in Ms Visual Basic 6.0 [...]

  2.   desty said:

    maaf sebelumnya..
    D3 MDP tahun 2003-2006
    S1 masiiiii dijalani_
    mo nanya,
    aq pernah baca dalam satu skripsi. klo dicoding bs buat set dalam bentuk laporan artinya jk di klik tombol tertentu bs terkonek ke print dan mengeluarkan hasil berupa laporan. tanpa harus buat data environment ataupun crystal report. bisa diterangi ga gimana coding nya.
    thx b4

  3.   Herianto said:

    Kalo cara untuk print langsung ke kertas tanpa harus men-set sebuah printing environment seperti Crystal Report, ada beberapa cara.
    1. Kalau kamu menggunakan komputer yang memiliki port paralel, dan printernya masih menggunakan port paralel untuk mencetak laporan, maka kamu bisa gunakan “Open “LPT1:” For Output As #1″

    Contoh codingnya :
    Open “LPT1:” For Output As #1
    Print #1, Tab(5); “Ini baris pertama”; Tab(50); “Ini untuk baris pertama setelah tab sebanyak 50 kali”
    Print #1, Tab(5); “Ini baris kedua”
    Close #1
    Nb. Tab itu adalah spasi.

    2. Kalau komputernya ngak ada lagi port paralel (biasanya laptop), gunakan perintah “Printer.Print”

    Contoh codingnya :
    Printer.Print Tab(10); “Ini baris pertama”; Tab(50); “Ini baris pertama setelah tab sebanyak 50 kali”
    Printer.Print Tab(10); “Ini baris kedua”
    Nb. Untuk penggunakan printer.print, kamu bisa setting orientation kertasnya, ukuran fontnya, sampai bold, italic, dsb melalui properties dalam class printer.
    Cth :
    Printer.Orientation = 1 ‘Ini untuk landscape
    Printer.FontBold = True ‘Ini untuk mem-bold font

    3. Yang ketiga, kamu bisa desain tampilan di sebuah form dengan menggunakan label2 dan textbox sehingga berbentuk sebuah report. Lalu siapkan sebuah tombol untuk mencetaknya. Di dalam tombol tadi kamu buat [NamaForm].PrintForm

  4.   desty said:

    Ok thx ya..

Leave a Reply