使用mschart控件时,如何将.data的字段变成变量?

环境监测技术 2017-06-25 04:00:11
代码如下:
With MSChart1
.chartType = 3
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.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 = 12
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 12
.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
.RowCount = rs.RecordCount
.Row = i + 1
.RowLabel = CStr(rs("测试时间"))
.Data = rs("重量")
就是上面这一句,我想把“重量”这个字段改成一个变量的形式,因为字段里面有重量、体积、长度等,我希望在前面用变量的形式赋值,比如
dim zd as string
zd从选择框中进行选择。
类似这种形式的,以便可以使用不同的字段。但是屡试不行。求助各位大家。

rs.MoveNext
Next
End With
...全文
209 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
环境监测技术 2017-07-02
  • 打赏
  • 举报
回复
引用 7 楼 zdingyun 的回复:
[quote=引用 6 楼 qq_33472235 的回复:] 这个好用。谢谢。我还有一些问题,今天没时间了。
有了解决问题的方法,就溜至大吉,LZ也不太礼貌了吧![/quote] 你误会了,没有及时结贴。谢谢你
zdingyun 2017-07-01
  • 打赏
  • 举报
回复
引用 6 楼 qq_33472235 的回复:
这个好用。谢谢。我还有一些问题,今天没时间了。
有了解决问题的方法,就溜至大吉,LZ也不太礼貌了吧!
环境监测技术 2017-06-25
  • 打赏
  • 举报
回复
这个好用。谢谢。我还有一些问题,今天没时间了。
zdingyun 2017-06-25
  • 打赏
  • 举报
回复
Private Sub Command15_Click()
    Dim sql As String
    Dim l As Integer
    Dim i As Integer
    Dim fieldName() As String
    sql = "select * from jishijilu" ' where madanhao='1'"
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
    cn.Open
    rs.CursorLocation = adUseClient
    rs.Open sql, cn, 1, 1, 1
    Dim sj As String
    sj = "shuju12"
    sj = Trim(sj)
    With MSChart1
      .chartType = 3
      .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
      .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
      .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
      .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 = 12
      .Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 12
      .Title.Text = "重量 变化曲线图"
      .ShowLegend = False
      .Data = rs(sj)
    End With
    cn.Close
End Sub
zdingyun 2017-06-25
  • 打赏
  • 举报
回复
With语句前使用数据查询代码,请查考以下方式,测试通过。
Private Sub Command15_Click()
Dim sql As String
Dim l As Integer
Dim i As Integer
Dim fieldName() As String
sql = "select * from jishijilu" ' where madanhao='1'"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, 1, 1, 1
Dim sj As String
sj = "shuju12"
sj = Trim(sj)
With MSChart1
.chartType = 3
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.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 = 12
.Plot.Axis(VtChAxisIdY, 0).AxisTitle.VtFont.Size = 12
.Title.Text = "重量 变化曲线图"
.ShowLegend = False
.Data = rs(sj)
End With
End Sub

环境监测技术 2017-06-25
  • 打赏
  • 举报
回复
Private Sub Form_Load() Dim item As String Combo1.AddItem "重量" Combo1.AddItem "体积" Combo1.AddItem "长度" 。。。。。 Private Sub Command1_Click() Select Case Combo1.ListIndex Case 0 item = "重量" Case 1 item = "体积" Case 2 item = "长度" 。。。。。。 .Data = rs(item) 就是这句不行!!!!!
环境监测技术 2017-06-25
  • 打赏
  • 举报
回复
好像不是这个意思。 卧室想先设置一个变量,变量可赋值不同的字段。 然后.data赋值=那个变量
zdingyun 2017-06-25
  • 打赏
  • 举报
回复
按类似以下代码方式:
    Dim sj As String
    sj = "shijian "
    sj = Trim(sj)
    Text3 = rs(sj)

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧