Click here to Skip to main content
15,879,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to bind database values to line chart in vb.net 2.0. Could you please tell which namespace and .dll will support for this. How to write code for dynamic chart. If anybody know this please help me.



Thanks
Posted

Take a look at my article on MSChart[^]. It shows how to retrieve values from the database and display them on the chart.

Hope it helps.
 
Share this answer
 
Comments
Jayanthi-SE 9-Jan-12 6:55am    
Hi,

will this chart support in vb.net 2.0 windows application
Wayne Gaylard 9-Jan-12 7:21am    
Yes, that is what I have used for the sample.
 
Share this answer
 
Hi,

We have to add Microsoft Chart Control 6.0 from com Components and Microsoft Activex Data Objects 2.0 Library from Add Reference->Com in our Toolbox


In Button_Click

VB
AxMSChart1.Plot.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).ValueScale.Auto = False
       AxMSChart1.Plot.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX).ValueScale.Auto = False

       AxMSChart1.Plot.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).ValueScale.Maximum = CDec(txt_maxvalue.Text)
       AxMSChart1.Plot.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).ValueScale.Minimum = CDec(txt_minvalue.Text)


VB
Dim db As New riskpro_net.dataaccess
       Dim i As Integer
       Dim ds As New DataSet
       'To display From and To date
       Dim fdate As String
       Dim tdate As String
       fdate = Format(CDate(dtp_from.Value), "yyyy-MM-dd")
       tdate = Format(CDate(dtp_to.Value), "yyyy-MM-dd")
       ds = db.retds("select * from tbl_chart where cdate between '" + fdate + "' and '" + tdate + "'", "tbl_chart")
       gv.ColumnCount = ds.Tables(0).Rows.Count + 1
       gv.RowCount = ds.Tables(0).Columns.Count + 1
       Dim s As Integer
       gv.Rows(0).Cells(0).Value = "Date"
       gv.Rows(0).Cells(0).Style.ForeColor = Color.DarkBlue
       gv.Rows(0).Cells(0).Style.Font = New Font(gv.Font, FontStyle.Bold)
       gv.Columns(0).Width = 120
       gv.Rows(1).Cells(0).Value = "Avg Realized Rate"
       gv.Rows(1).Cells(0).Style.ForeColor = Color.DarkBlue
       gv.Rows(1).Cells(0).Style.Font = New Font(gv.Font, FontStyle.Bold)
       gv.Rows(2).Cells(0).Value = "Avg Invoiced Rate"
       gv.Rows(2).Cells(0).Style.ForeColor = Color.DarkBlue
       gv.Rows(2).Cells(0).Style.Font = New Font(gv.Font, FontStyle.Bold)
       gv.Rows(3).Cells(0).Value = "Avg Spot Rate"
       gv.Rows(3).Cells(0).Style.ForeColor = Color.DarkBlue
       gv.Rows(3).Cells(0).Style.Font = New Font(gv.Font, FontStyle.Bold)

       For s = 1 To gv.ColumnCount - 1
           gv.Columns(s).Width = 68
       Next

       For s = 1 To ds.Tables(0).Rows.Count
           gv.Rows(0).Cells(s).Value = CDate(ds.Tables(0).Rows(s - 1)("cdate")).ToString("dd-MMM-yy")
           gv.Rows(0).Cells(s).Style.ForeColor = Color.DarkBlue
           gv.Rows(0).Cells(s).Style.Font = New Font(gv.Font, FontStyle.Bold)
           gv.Rows(1).Cells(s).Value = CDec(ds.Tables(0).Rows(s - 1)("AvgRealizedRate"))
           gv.Rows(2).Cells(s).Value = CDec(ds.Tables(0).Rows(s - 1)("AvgInvoicedRate"))
           gv.Rows(3).Cells(s).Value = CDec(ds.Tables(0).Rows(s - 1)("AvgSpotRate"))
       Next

       AxMSChart1.RowCount = ds.Tables(0).Rows.Count
       AxMSChart1.ColumnCount = ds.Tables(0).Columns.Count - 1
       For i = 1 To AxMSChart1.RowCount
           AxMSChart1.Row = i

           AxMSChart1.RowLabel = CDate(ds.Tables(0).Rows(i - 1)("cdate")).ToString("MMM-yy")

           'To set Row Header Text
           AxMSChart1.Column = 1
           AxMSChart1.Data = ds.Tables(0).Rows(i - 1)("AvgRealizedRate")
           AxMSChart1.ColumnLabel = "Avg Realized Rate"

           AxMSChart1.Column = 2
           AxMSChart1.Data = ds.Tables(0).Rows(i - 1)("AvgInvoicedRate")
           AxMSChart1.ColumnLabel = "Avg Invoiced Rate"

           AxMSChart1.Column = 3
           AxMSChart1.Data = ds.Tables(0).Rows(i - 1)("AvgSpotRate")
           AxMSChart1.ColumnLabel = "Avg Spot Rate"

       Next
       AxMSChart1.Visible = True
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900