⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.frm

📁 mantis项目管理系统中能够用到的报表显示所需的控件
💻 FRM
字号:
VERSION 5.00
Begin VB.Form GRAPH 
   Caption         =   "MSGraph.Chart.8图表示例   枕善居发布 http://www.mndsoft.com"
   ClientHeight    =   4950
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   11880
   Icon            =   "Graph.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4950
   ScaleWidth      =   11880
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame fra_Cont 
      Height          =   1650
      Left            =   0
      TabIndex        =   1
      ToolTipText     =   "YOU CAN RESIZE FORM AND SEE!!!"
      Top             =   3255
      Width           =   11835
      Begin VB.CommandButton cmdPrint 
         Caption         =   "打印(&P)"
         Height          =   375
         Left            =   8730
         TabIndex        =   15
         Top             =   1080
         Width           =   1215
      End
      Begin VB.CommandButton cmdRefresh 
         Caption         =   "刷新(&R)"
         Height          =   375
         Left            =   8715
         TabIndex        =   12
         Top             =   525
         Width           =   1245
      End
      Begin VB.Frame fra_ChartType 
         Caption         =   "选项"
         Height          =   1395
         Left            =   240
         TabIndex        =   4
         Top             =   150
         Width           =   3045
         Begin VB.OptionButton OptVal 
            Caption         =   "线条"
            Height          =   195
            Index           =   6
            Left            =   120
            TabIndex        =   11
            Top             =   240
            Width           =   735
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "三维圆柱"
            Height          =   345
            Index           =   5
            Left            =   1800
            TabIndex        =   10
            Top             =   975
            Width           =   1125
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "圆柱"
            Height          =   180
            Index           =   2
            Left            =   105
            TabIndex        =   9
            Top             =   1050
            Width           =   915
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "三维条形"
            Height          =   195
            Index           =   4
            Left            =   1800
            TabIndex        =   8
            Top             =   780
            Width           =   1080
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "三维面积"
            Height          =   195
            Index           =   3
            Left            =   1800
            TabIndex        =   7
            Top             =   480
            Width           =   1185
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "条形"
            Height          =   195
            Index           =   1
            Left            =   120
            TabIndex        =   6
            Top             =   780
            Width           =   975
         End
         Begin VB.OptionButton OptVal 
            Caption         =   "面积"
            Height          =   195
            Index           =   0
            Left            =   120
            TabIndex        =   5
            Top             =   510
            Width           =   945
         End
      End
      Begin VB.ListBox lstFields 
         Height          =   960
         Left            =   6210
         MultiSelect     =   1  'Simple
         TabIndex        =   3
         Top             =   495
         Width           =   2295
      End
      Begin VB.ListBox lst_Tables 
         Height          =   960
         ItemData        =   "Graph.frx":08CA
         Left            =   3720
         List            =   "Graph.frx":08D7
         TabIndex        =   2
         Top             =   480
         Width           =   2295
      End
      Begin VB.Label Label1 
         Caption         =   "显示的字段"
         Height          =   255
         Left            =   6210
         TabIndex        =   14
         Top             =   240
         Width           =   1935
      End
      Begin VB.Label Label2 
         Caption         =   "数据库"
         Height          =   255
         Left            =   3720
         TabIndex        =   13
         Top             =   240
         Width           =   1935
      End
   End
   Begin VB.OLE Ole_Graph 
      AutoActivate    =   0  'Manual
      AutoVerbMenu    =   0   'False
      Class           =   "MSGraph.Chart.8"
      Height          =   3255
      Left            =   0
      OleObjectBlob   =   "Graph.frx":0908
      TabIndex        =   0
      Top             =   0
      Width           =   13635
   End
End
Attribute VB_Name = "GRAPH"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'****************************************************************************
'人人为我,我为人人
'枕善居汉化收藏整理
'发布日期:05/06/17
'描  述:MSGraph.Chart.8图表示例
'网  站:http://www.mndsoft.com/
'e-mail:mnd@mndsoft.com
'OICQ  : 88382850
'****************************************************************************

Option Explicit
Dim strTbl As String '表声明
Public db As Database

Private Sub cmdPrint_Click()
    '把打印机设置横向打印
    ChngPrinterOrientationLandscape Me
    Me.PrintForm
End Sub

Private Sub cmdRefresh_Click()
    '刷新无字段选择则忽略
    If lstFields.SelCount < 1 Then Exit Sub
    
    '重绘图
    DoGraph GetSelect & " FROM " & strTbl & " ORDER BY DateCollected "
End Sub

Private Function GetRecordSet(Str As String) As Recordset
    '动态记录集
    Set db = OpenDatabase(App.Path & "\TestDB.mdb")
    Set GetRecordSet = db.OpenRecordset(Str)
End Function

Private Function Graphing(Str As String) As String
    Dim RST As Recordset
    Dim X As Integer
    Dim TB, NL
    Graphing = ""
    '制表符
    TB = Chr(9)
    '新线条
    NL = Chr(10)
    '外部空白
    Set RST = GetRecordSet(Str)
    
    '标题
    For X = 1 To RST.Fields.Count - 1
        Graphing = Graphing + TB
        Graphing = Graphing & RST(X).Name
    Next
    
    '数据..
    While Not RST.EOF
        Graphing = Graphing + NL
        For X = 0 To RST.Fields.Count - 1
            Graphing = Graphing & RST(X)
            If X <> RST.Fields.Count Then
                Graphing = Graphing + TB
            End If
        Next
    RST.MoveNext
    Wend
    Set RST = Nothing
End Function

Private Sub Form_Load()
    Dim Str As String
    '默认图表类型
    OptVal_Click 4
    OptVal_Click 3
    
    strTbl = "tbl_Collections" '默认数据源
    '默认绘制的数据
    Str = "Select DateCollected AS [日期], Amount AS [实际金额], 700 AS 对象 FROM tbl_Collections ORDER BY DateCollected "
    DoGraph Str '绘图
    LoadFields
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    Ole_Graph.Width = Me.Width - 150
    Ole_Graph.Height = Me.Height - 2300
    fra_Cont.Top = Me.Height - 2200
End Sub

Private Sub Form_Unload(Cancel As Integer)
    db.Close '关闭连接
    Set db = Nothing '释放内存
End Sub

Private Sub lst_Tables_Click()
    strTbl = lst_Tables.Text '改变数据源
    LoadFields '载入字段
End Sub

Private Sub OptVal_Click(Index As Integer)
    Dim OptionValue As Integer
    Select Case Index
        Case 0
            OptionValue = 1 '面积
        Case 1
            OptionValue = 2 '条形
        Case 2
            OptionValue = 3 '圆柱
        Case 3
            OptionValue = -4098 '三维面积
        Case 4
            OptionValue = -4099 '三维条形
        Case 5
            OptionValue = -4100 '三维圆柱
        Case 6
            OptionValue = 4 '线条
    End Select
        Ole_Graph.Object.Application.Chart.Type = OptionValue
    
End Sub

'绘图
Private Sub DoGraph(Str As String)
    Dim DataToTrend As String
    With Ole_Graph
       '格式
       .Format = "CF_TEXT"
       '缩放
       .SizeMode = 1
    End With
    
    DataToTrend = Graphing(Str)
    'OLE.Object.Application.Chart.Type = 4
    With Ole_Graph
       '激活隐藏
       .DoVerb -3
       If .AppIsRunning Then
          '数据
          .DataText = DataToTrend
          '更新
          .Update
       Else
          MsgBox "图表OLE对象不存在,请先安装该对象.", , "提示"
       End If
    End With
End Sub

Private Sub LoadFields()
    Dim Str As String
    Dim RST As Recordset
    Dim I As Integer
    
    '清空 ListBox
    lstFields.Clear
    
    '查询字段
    Str = "Select * from " & strTbl & ""
    Set RST = GetRecordSet(Str)
    If RST.EOF Then Exit Sub '空记录退出
    For I = 1 To RST.Fields.Count - 1
        lstFields.AddItem (RST(I).Name) '添加
    Next
    Set RST = Nothing
End Sub

Function GetSelect() As String '获取绘制的字段集合
Dim I As Integer
GetSelect = ""
If lstFields.SelCount > 0 Then
    For I = 0 To lstFields.ListCount - 1 '字段号
        If lstFields.Selected(I) = True Then
            lstFields.ListIndex = I
            If GetSelect <> "" Then
                GetSelect = GetSelect & ", " & lstFields
            Else
                GetSelect = "Select DateCollected, " & lstFields.Text
            End If
        End If
    Next
End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -