如何将数据库值绑定到图表 [英] How to binding database values to chart
本文介绍了如何将数据库值绑定到图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数据库值绑定到vb.net 2.0中的折线图.您能否告诉我们哪个名称空间和.dll将支持此功能.如何为动态图表编写代码.如果有人知道这一点,请帮助我.
谢谢
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
推荐答案
看看我在 MSChart上的文章 [ ^ ].它显示了如何从数据库中检索值并将其显示在图表上.
希望对您有所帮助.
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.
.NET的灵活图表库 [ ^ ]
你好,
我们必须从com组件中添加Microsoft Chart Control 6.0,并从工具箱中的Add Reference-> Com中添加Microsoft Activex Data Objects 2.0 Library
在Button_Click
中
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
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)
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
这篇关于如何将数据库值绑定到图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文