Quantcast
Viewing all articles
Browse latest Browse all 1448

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
Image may be NSFW.
Clik here to view.
 
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles