我用vb的mschart连接access数据库做了一个显示数据的直方图。我现在想用一个鼠标移动事件。就是当鼠标移动到某一个直方条上。text1.text能显示和直方条相对应的数据。

解决方案 »

  1.   

    能不能把你的代码发给我,我也研究一下?
    [email protected]
      

  2.   

    前面的几个回答我都不是很满意。下面是我的代码。
    Option Explicit
    Dim Res As New ADODB.Connection
    Dim Rec As New ADODB.Recordset
    Private Sub WidthMSchart()With MSChart1
        If Not Rec.EOF Then
            .TitleText = "" & Rec.Fields("" & frmMain.Label2.Caption & ".名称") & ""               'MSChart控件标题赋值
            .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
                    
            If Rec.Fields("" & frmMain.Label2.Caption & ".最新价") < 10 Then
                .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") - 0.5
                .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") + 1
                .Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10
            ElseIf Rec.Fields("" & frmMain.Label2.Caption & ".最新价") < 20 _
                              And Rec.Fields("" & frmMain.Label2.Caption & ".最新价") > 10 Then
                .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") - 1
                .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") + 3.5
                .Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10
            Else
                .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") - 1
                .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Rec.Fields("" & frmMain.Label2.Caption & ".最新价") + 4
                .Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10
            End If
                .Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
                
                .ColumnCount = 1
                .FootnoteText = Rec.Fields("" & frmMain.Label2.Caption & ".日期")
                
            Dim I As Integer
            For I = 1 To .Plot.SeriesCollection.Count            .Plot.SeriesCollection(I).DataPoints(-1).Brush.FillColor.Set 255, 0, 0
                .Plot.SeriesCollection(I).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint        Next
            .ShowLegend = True                     '显示图例
        End If
    End WithEnd Sub
    Private Sub Form_Load()
    CenterForm frmTrend
    DTPicker1.Value = Now
    MSChart1.DoSetCursor = False
    Res.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
             & App.Path & "\hushiAgu.mdb;Persist Security Info=False;Jet OLEDB:Database Password=111111"
    Res.CursorLocation = adUseClient
    cmdWeekly_Click
    End Sub
    Private Sub cmdWeekly_Click()
    DTPicker2.Value = DateAdd("d", -7, Now)
    DisplyMSChart
    MSChart1.Plot.Axis(VtChAxisIdX).AxisScale.Hide = False
    Set MSChart1.DataSource = RecWidthMSchart
    MSChart1.ChartType = VtChChartType2dBar
    End Sub