想要实现在折线上显示数据源的功能,看到C#的chart控件可以轻松设置erStyle属性来实现,但是在C++ MFC的 ChartCtrll里找不到这个属性,不知道可以用什么方法来实现?

解决方案 »

  1.   

    仅供参考,尽管是VB6:VERSION 5.00
    Object = "{65E121D4-0C60-11D2-A9FC-0000F8754DA1}#2.0#0"; "mschrt20.ocx"
    Begin VB.Form Form1
       Caption         =   "Chart"
       ClientHeight    =   3480
       ClientLeft      =   5190
       ClientTop       =   4005
       ClientWidth     =   11505
       ClipControls    =   0   'False
       ForeColor       =   &H80000017&
       KeyPreview      =   -1  'True
       LinkTopic       =   "Form1"
       MaxButton       =   0   'False
       MousePointer    =   2  'Cross
       ScaleHeight     =   3480
       ScaleWidth      =   11505
       StartUpPosition =   2  '屏幕中心
       Begin VB.PictureBox Picture1
          Appearance      =   0  'Flat
          BorderStyle     =   0  'None
          ForeColor       =   &H80000008&
          Height          =   375
          Left            =   10200
          ScaleHeight     =   375
          ScaleWidth      =   1215
          TabIndex        =   2
          Top             =   3000
          Visible         =   0   'False
          Width           =   1215
       End
       Begin MSChart20Lib.MSChart pie
          Height          =   3450
          Left            =   0
          OleObjectBlob   =   "Chart.frx":0000
          TabIndex        =   0
          Top             =   0
          Width           =   11475
       End
       Begin VB.Label Label1
          Alignment       =   2  'Center
          Caption         =   "0"
          BeginProperty Font
             Name            =   "宋体"
             Size            =   42
             Charset         =   134
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   855
          Left            =   4200
          TabIndex        =   1
          Top             =   1320
          Width           =   3015
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit
    Dim i As Integer
    Dim f As Integer
    Dim ln As String
    Dim n As Integer
    Dim c As Integer
    Dim g As Integer
    Dim d As Double
    Dim cn As Integer
    Dim cc(1 To 7) As Long
    Private Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii = 27 Then End 'form
    End Sub
    Private Sub Form_Load()
    '    On Error GoTo FLEND
        cc(1) = RGB(0, 0, 255)
        cc(2) = RGB(10, 128, 10)
        cc(3) = RGB(255, 0, 0)
        cc(4) = RGB(255, 0, 255)
        cc(5) = RGB(255, 255, 0)
        cc(6) = RGB(255, 255, 255)
        cc(7) = RGB(0, 255, 255)
        f = FreeFile()
        Open "c:\data.txt" For Input As #f
        Line Input #f, ln
        Close #f    Open "c:\data1ln.txt" For Output As #f
        Print #f, ln
        Close #f    Open "c:\data1ln.txt" For Input As #f
        cn = 0
        Do
            If EOF(f) Then Exit Do
            Input #f, d
            cn = cn + 1
        Loop
        Close #f
        If cn <= 0 Or cn > 7 Then End 'form
        Open "c:\data.txt" For Input As #f
        pie.Enabled = False
        'pie.DoSetCursor = False
        pie.MousePointer = VtMousePointerCross
        pie.Top = 0
        pie.Left = 0
        pie.Width = Form1.Width - 120
        pie.Height = Form1.Height - 390
        pie.chartType = VtChChartType2dLine
        pie.ColumnCount = cn
        Label1.Caption = "0"
        Label1.Visible = True
        pie.Visible = False
        Form1.Show
        n = Val(Command$)
        If n <= 0 Then
            n = 0
            Do
                If EOF(f) Then Exit Do
                Line Input #f, ln
                n = n + 1
            Loop
            Close #f
            Open "c:\data.txt" For Input As #f
        End If
        On Error Resume Next
        pie.RowCount = n
        i = 1
        Do
            If EOF(f) Then Exit Do
            pie.Row = i
            If i Mod 10 = 1 Then pie.RowLabel = CStr(i - 1)
            For c = 1 To cn
                Input #f, d
                pie.Column = c
                pie.Data = d
            Next
            i = i + 1
            If i Mod 100 = 0 Then Label1.Caption = CStr(i): DoEvents
            If i > n Then Exit Do
        Loop
        Close #f
        Label1.Visible = False
        If i < 500 Then
            g = 10
        ElseIf i < 5000 Then
            g = 100
        Else
            g = 1000
        End If
        With pie.Plot.Axis(VtChAxisIdX)
        '    .AxisScale.Type = VtChScaleTypeLinear
        '    .ValueScale.MajorDivision = g
        '    .ValueScale.MinorDivision = g
            .CategoryScale.Auto = False         '设置为人工缩放。
            .CategoryScale.DivisionsPerLabel = g '每g个单位显示标签。
            .CategoryScale.DivisionsPerTick = g  '每g个单位显示刻度。
            .CategoryScale.LabelTick = True   '在刻度标记顶端显示标签。
        End With
        pie.Visible = True
        Exit Sub
    FLEND:
        End 'Form
    End Sub
    Private Sub Form_Resize()
        pie.Width = Form1.Width - 120
        pie.Height = Form1.Height - 390
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        End 'form
    End Sub
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim whichPart As Integer, whichSeries As Integer
    Dim whichNumber As Integer
    Dim dd(1 To 7) As Double
    Dim tip As String
        'Debug.Print "FORMmove " + CStr(X) + "," + CStr(Y)
        pie.TwipsToChartPart X, Y, whichPart, whichSeries, whichNumber, 0, 0
        pie.AllowSeriesSelection = False
        If whichPart <> VtChPartTypePoint Then
            Picture1.Visible = False
        Else
            Picture1.Top = Y + pie.Top - 270
            Picture1.Left = X + pie.Left + 90
            pie.Row = whichNumber
            For c = 1 To cn
                pie.Column = c
                dd(c) = pie.Data
            Next
            Picture1.BackColor = RGB(160, 160, 160)
            Picture1.ForeColor = RGB(0, 0, 0)
            Picture1.Cls
            Picture1.CurrentY = 15
            Picture1.Print " " + CStr(whichNumber);
            tip = " " + CStr(whichNumber)
            For c = 1 To cn
                Picture1.ForeColor = cc(c)
                Picture1.Print " " + CStr(dd(c));
                tip = tip + " " + CStr(dd(c))
            Next
            Picture1.Width = (Len(tip) * 6 + 5) * 15
            Picture1.Height = 14 * 15
            Picture1.Visible = True
        End If
    End Sub
      

  2.   

    设计时,在CharCtrl控件上双击鼠标左键,弹出该控件的属性页,设置相关该控件的参数。