关于mschart问题,代码错误1119,对象未初始化或无效
Private Sub Command1_Click()Dim i As Integer
rs.Open "select 车速,sum(case when 样件序列='3' then 振动级 end ) As '第三组' ,sum(case when 样件序列='4' then 振动级 end ) As '第四组' from 加速度测试结果 where 品牌='" & Combo1.Text & "'and 驱动形式='" & Combo2.Text & "' and 平台='" & Combo5.Text & "' and 减震形式='" & Combo4.Text & "' and 悬置形式='" & Combo3.Text & "' group by 车速 ", conn, adOpenKeyset, adLockOptimistic
' Set MSChart1.DataSource = rs
With MSChart1
'// 以线条方式显示
.chartType = 3
'// 把刻录改为手工方式
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 设置最大值
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 127
'// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 118
'// 设置每格为 1
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 1
'// 增加测试数据
.ColumnCount = 3
'//轴坐标标题
.Plot.Axis(VtChAxisIdX, 0).AxisTitle = "车速"
.Plot.Axis(VtChAxisIdY, 0).AxisTitle = "振动级(dB)"
'//轴坐标标题字体大小的设置
.Plot.Axis(VtChAxisIdX, 0).AxisTitle.VtFont.Size = 15
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 15
'//设置图表标题
.Title.Text = "振动级"
'// 将图表作为图例的背景。
.ShowLegend = False
'// 标记每个点的值
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 = rs("车速")
.Data = rs("第三组")
.Column = 2
.Data = rs("第四组")
rs.MoveNext
Next
End With
End Sub