如果你的datagird绑定这数据库。你直接读取那2列的字段。
Private Sub Command1_Click()
On Error Resume Next
Dim i As Integer
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString =“数据库连接字符串”
conn.CursorLocation = adUseClient
conn.Open
rs.Open "select 字段1,字段2 from 表名", conn, adOpenKeyset, adLockOptimistic
With MSChart1
*// 以线条方式显示
.chartType = 3
*// 把刻录改为手工方式
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
*// 设置最大值
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1
*// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0.7
*// 设置每格为 1
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
*// 设置总列数
.ColumnCount = 1
*//轴坐标标题
.Plot.Axis(VtChAxisIdX, 0).AxisTitle = "日期"
.Plot.Axis(VtChAxisIdY, 0).AxisTitle = "密度"
*//轴坐标标题字体大小的设置
.Plot.Axis(VtChAxisIdX, 0).AxisTitle.VtFont.Size = 15
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 15
*//设置图表标题
.Title.Text = "密度折线图"
*// 显示图例说明
.ShowLegend = True
*// 标记每个点的值
For i = 1 To .Plot.SeriesCollection.Count
.Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Next
If rs.RecordCount > 0 Then
rs.MoveFirst
Else
Exit Sub
End If
For i = 0 To rs.RecordCount - 1
.Column = 1
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("qy_date"))
.Data = rs("qy_midu")
.ColumnLabel = "密度" *图例说明文字
rs.MoveNext
Next
End With
End Sub