Results 1 to 3 of 3

Thread: VB6 - MSChart XY Scatter Demo

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    VB6 - MSChart XY Scatter Demo

    MSChart is a very complex control. Sometimes it can be frustrating to get just what you want out of it.

    An example is a "scatter plot" of the sort shown here.

    Code:
    Option Explicit
    
    'Just plop an instance of MSChart as MSChart1 onto a Form.
    
    Private Sub Form_Load()
        Dim Series1 As Variant
        Dim Series2 As Variant
        Dim Series3 As Variant
        Dim Series As Integer
        Dim I As Integer
        Dim Row As Integer
    
        'Hold series data in Variant arrays here, as (X, Y) pairs
        'that follow each other:
        Series1 = Array(12, 20, 3, 10, 15, 20, 4, 50, 50, 27)
        Series2 = Array(1, 12, 23, 9, 48, 25, 16, 16, 30, 37)
        Series3 = Array(1, 43, 45, 45, 4, 25, 39, 5, 13, 6)
        
        With MSChart1
            .chartType = VtChChartType2dXY
            .RowCount = (UBound(Series1) + 1) \ 2
            .ColumnCount = 6 '2 columns per series, 3 series.
            
            'Set up each Series for small circles with no lines.
            For Series = 1 To 3
                With .Plot.SeriesCollection((Series - 1) * 2 + 1)
                    .SeriesType = VtChSeriesType2dXY
                    .ShowLine = False
                    With .SeriesMarker
                        .Show = True
                        .Auto = False
                    End With
                    With .DataPoints(-1).Marker
                        .Style = VtMarkerStyleFilledCircle
                        .Size = ScaleX(7, vbPixels, vbTwips)
                        With .Pen.VtColor
                            Select Case Series
                                Case 1
                                    .Set 192, 64, 64 'Red.
                                Case 2
                                    .Set 64, 64, 192 'Blue.
                                Case 3
                                    .Set 64, 192, 64 'Green.
                            End Select
                        End With
                    End With
                End With
            Next
        
            For I = 0 To UBound(Series1) Step 2
                Row = I \ 2 + 1
                .DataGrid.SetData Row, 1, Series1(I), False
                .DataGrid.SetData Row, 2, Series1(I + 1), False
                
                .DataGrid.SetData Row, 3, Series2(I), False
                .DataGrid.SetData Row, 4, Series2(I + 1), False
                
                .DataGrid.SetData Row, 5, Series3(I), False
                .DataGrid.SetData Row, 6, Series3(I + 1), False
            Next
        End With
    End Sub
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - MSChart XY Scatter Demo

    A arrays of data are just there to keep the example concise. Obviously for real applications you'd use a bound data source or read and add data from a file, etc.

    The example I gave above was meant as a more useful alternative to the one provided at:

    How To Plot X/Y Coordinate Values on a Scatter Chart

    That example is flawed, but the article does provide useful information so it is worth reading.


    You might also find these articles of interest:

    How To Handle Missing DataPoints with MSChart

    How To Use the UniformAxis Property to Control Chart Scaling

    PRB: Cannot Have Secondary Y Axis with MSChart XY Scatterchart

    PRB: Cannot Set Marker Size or Style for MSChart

    How To Set a Custom Range for Value Axis with MSChart Control

    FIX: Setting MSChart's AxisScale Type to Logarithmic Hangs VB

    How To Print the Contents of the MS Chart Control


    Screenshot of the Microsoft "How to plot..." example, showing how it is deficient:
    Attached Images Attached Images  
    Last edited by dilettante; Jan 2nd, 2013 at 03:21 AM.

  3. #3
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    162

    Re: VB6 - MSChart XY Scatter Demo

    dilettante, maybe you remember, is it can changing sizes of some plots?
    like bubble chart
    Ten Years After - 01 You Give Me Loving

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width