Mschart例子:
MSDN的samples\vb98\chrtsamp

解决方案 »

  1.   

    MSChart 控件
                以图形方式显示数据的图表。语法MSChart说明MSChart 控件支持以下特性: 真三维表示。
    支持所有主要的图表类型。
    数据网格成员支持随机数据,数据数组。 
    MSChart 控件与数据网格(DataGrid 对象)相关连。这种数据网格是存有已图表化数据的表。数据网格中也包括用于在图表中标识系列和分类的标签。图表应用程序的设计人员通过从表单或数组中插入或输入数据,来给数据网格填充信息。MSChart 控件示例
    下面的示例显示一个具有 8 行 8 列数据的三维图表,并设置了图例的参数。Private Sub Command1_Click()
       With MSChart1
          '显示一个具有 8 行 8 列数据的三维图表。
          .ChartType = VtChChartType3dBar
          .ColumnCount = 8
          .RowCount = 8
          For column = 1 To 8
             For row = 1 To 8
                .Column = column
                .Row = row
                .Data = row * 10
             Next row
          Next column
          '将图表作为图例的背景。
          .ShowLegend = True
          .SelectPart VtChPartTypePlot, index1, index2, _
          index3, index4
          .EditCopy
          .SelectPart VtChPartTypeLegend, index1, _
          index2, index3, index4
          .EditPaste
       End With
    End Sub
      

  2.   

    你也不用用API吧,MSCHART可以解决你的问题了,如果你一定要生成一幅“图”的话,也可以用MSCHART的EditCopy方法先COPY一幅“图”到剪贴板,然后用GetClipboardData 方法得到图,保存到文件或者流对象,都可以。如果不喜欢使用控件,也可以先创建一个stdPicture对象,使用各种画图方法画你喜欢的东西,然后SavePicture到文件也可以啊,没必要使用API。使用API的话,先创建一个图的DC,然后在该DC上绘画,不会比上一个方法有大的性能改进。
      

  3.   

    没有具体的代码吗,我已经使用了api,不想回头了!
      

  4.   


    用api pie:
    Const PS_DOT = 2
    Const PS_SOLID = 0
    Const RGN_AND = 1
    Const RGN_COPY = 5
    Const RGN_OR = 2
    Const RGN_XOR = 3
    Const RGN_DIFF = 4
    Const HS_DIAGCROSS = 5
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Type LOGPEN
        lopnStyle As Long
        lopnWidth As POINTAPI
        lopnColor As Long
    End Type
    Private Declare Function CreateHatchBrush Lib "gdi32" (ByVal nIndex As Long, ByVal crColor As Long) As Long
    Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
    Private Declare Function CreatePenIndirect Lib "gdi32" (lpLogPen As LOGPEN) As Long
    Private Declare Function CreateRectRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
    Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
    Private Declare Function FloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function InvertRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
    Private Declare Function OffsetRgn Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
    Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function RoundRect Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Me.ScaleMode = vbPixels
    End Sub
    Private Sub Form_Paint()
        Dim hHBr As Long, R As RECT, hFRgn As Long, hRRgn As Long, hRPen As Long, LP As LOGPEN
        Dim hFFBrush As Long, mIcon As Long, Cnt As Long
        'Clear the form
        Me.Cls
        'Set the rectangle's values
        SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
        'Create a new brush
        hHBr = CreateHatchBrush(HS_DIAGCROSS, vbRed)
        'Draw a frame
        FrameRect Me.hdc, R, hHBr
        'Draw a rounded rectangle
        hFRgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, (Me.ScaleWidth / 3) * 2, (Me.ScaleHeight / 3) * 5)
        'Draw a frame
        FrameRgn Me.hdc, hFRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight
        'Invert a region
        InvertRgn Me.hdc, hFRgn
        'Move our region
        OffsetRgn hFRgn, 10, 10
        'Create a new region
        hRRgn = CreateRectRgnIndirect(R)
        'Combine our two regions
        CombineRgn hRRgn, hFRgn, hRRgn, RGN_XOR
        'Draw a frame
        FrameRgn Me.hdc, hRRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight
        'Crete a new pen
        hRPen = CreatePen(PS_SOLID, 5, vbBlue)
        'Select our pen into the form's device context and delete the old pen
        DeleteObject SelectObject(Me.hdc, hRPen)
        'Draw a rectangle
        Rectangle Me.hdc, Me.ScaleWidth / 2 - 25, Me.ScaleHeight / 2 - 25, Me.ScaleWidth / 2 + 25, Me.ScaleHeight / 2 + 25
        'Delete our pen
        DeleteObject hRPen
        LP.lopnStyle = PS_DOT
        LP.lopnColor = vbGreen
        'Create a new pen
        hRPen = CreatePenIndirect(LP)
        'Select our pen into the form's device context
        SelectObject Me.hdc, hRPen
        'Draw a rounded rectangle
        RoundRect Me.hdc, Me.ScaleWidth / 2 - 25, Me.ScaleHeight / 2 - 25, Me.ScaleWidth / 2 + 25, Me.ScaleHeight / 2 + 25, 50, 50
        'Create a new solid brush
        hFFBrush = CreateSolidBrush(vbYellow)
        'Select this brush into our form's device context
        SelectObject Me.hdc, hFFBrush
        'Floodfill our form
        FloodFill Me.hdc, Me.ScaleWidth / 2, Me.ScaleHeight / 2, vbBlue
        'Delete our brush
        DeleteObject hFFBrush
        'Create a new solid brush
        hFFBrush = CreateSolidBrush(vbMagenta)
        'Select our solid brush into our form's device context
        SelectObject Me.hdc, hFFBrush
        'Draw a Pie
        Pie Me.hdc, Me.ScaleWidth / 2 - 15, Me.ScaleHeight / 2 - 15, Me.ScaleWidth / 2 + 15, Me.ScaleHeight / 2 + 15, 20, 20, 20, 20
        'Extract icons from 'shell32.dll' and draw them on the form
        For Cnt = 0 To Me.ScaleWidth / 32
            ExtractIconEx "shell32.dll", Cnt, mIcon, ByVal 0&, 1
            DrawIcon Me.hdc, 32 * Cnt, 0, mIcon
            DestroyIcon mIcon
        Next Cnt
        'Clean up
        DeleteObject hFFBrush
        DeleteObject hRPen
        DeleteObject hRRgn
        DeleteObject hFRgn
        DeleteObject hHBr
    End Sub
    Private Sub Form_Resize()
        Form_Paint
    End Sub
      

  5.   

    Pie VB声明 
    Declare Function Pie Lib "gdi32" Alias "Pie" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long 
    说明 
    象注解里那样画一个饼图,X1,Y1,X2,Y2指定椭圆的一个约束矩形。从矩形的中心分别向X3,Y3和X4,Y4画一条线,这两条线与椭圆的交点定义了饼图占据椭圆的面积 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数        类型及说明 
    hdc Long,  指定一个显示场景的句柄 
    X1,Y1 Long,指定椭圆约束矩形的左上角位置 
    X2,Y2 Long,指定椭圆约束矩形的右下角位置 
    X3,Y3 Long,指定饼图的一个斜边 
    X4,Y4 Long,指定饼图的另一个斜边 
    注解  在win95和win16中,约束矩形的宽度和高度必须在3-32766之间
    参考Arc函数 
      

  6.   

    在有背景的image上能够用api画出坐标吗,我怎么都画不出来呢!
    代码如下:
    Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal x3 As Long, ByVal y3 As Long, ByVal x4 As Long, ByVal y4 As Long) As Long
    Private Declare Function Chord Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal x3 As Long, ByVal y3 As Long, ByVal x4 As Long, ByVal y4 As Long) As Long
    Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long) As Long
    Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
    Private Declare Function FloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongPrivate Sub Command1_Click()
    'P1.Cls
    MoveToEx Form1.P1.hdc, 50, P1.Height - 80, ByVal 0
    LineTo Form1.P1.hdc, P1.Width - 50, P1.Height - 80
    MoveToEx Form1.P1.hdc, P1.Width - 50, P1.Height - 80, ByVal 0
    LineTo Form1.P1.hdc, P1.Width - 60, P1.Height - 78
    MoveToEx Form1.P1.hdc, P1.Width - 50, P1.Height - 80, ByVal 0
    LineTo Form1.P1.hdc, P1.Width - 60, P1.Height - 82
    MoveToEx Form1.P1.hdc, 50, P1.Height - 80, ByVal 0
    LineTo Form1.P1.hdc, 50, 20
    MoveToEx Form1.P1.hdc, 50, 20, ByVal 0
    LineTo Form1.P1.hdc, 52, 30
    MoveToEx Form1.P1.hdc, 50, 20, ByVal 0
    LineTo Form1.P1.hdc, 48, 30
    P1.FillColor = &H80000007
    'P1.FillColor = RGB(0, 0, 0)
    'P1.Line (50, P1.Height - 80)-(P1.Width - 50, P1.Height - 80), , B
    'P1.Line (50, P1.Height - 80)-(50, 30), , B
    'P1.Line (50, 30)-(48, 40), , B
    'P1.Line (50, 30)-(52, 40), , B
    'P1.Line (P1.Width - 50, P1.Height - 80)-(P1.Width - 60, P1.Height - 78), , B
    'P1.Line (P1.Width - 50, P1.Height - 80)-(P1.Width - 60, P1.Height - 82), , B
    End SubPrivate Sub Command2_Click()
    P1.Line (0, 0)-(360, 360)
           Dim lY As Long
           Dim lScaleHeight As Long
           Dim lScaleWidth As Long
           P1.ScaleMode = vbPixels
           lScaleHeight = P1.ScaleHeight
           lScaleWidth = P1.ScaleWidth
           P1.DrawStyle = vbInvisible
           P1.FillStyle = vbFSSolid
           For lY = 0 To lScaleHeight
               P1.FillColor = RGB(155 + (lY * 100) \ lScaleHeight, 255, 155 + (lY * 100) \ lScaleHeight)
               P1.Line (-1, lY - 1)-(lScaleWidth, lY + 1), , B
           Next lY
    End SubPrivate Sub Command3_Click()
    End
    End SubPrivate Sub Form_Load()
    Form1.Move 0, 0, Screen.Width, Screen.Height
    P1.Move 200, 50, 400, 300
    End Sub