Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleUse MSChart to plot two curves with unrelated X values
KeywordsMSChart, graph, database, chart
CategoriesGraphics, Controls
 
When the program loads, it places random data in the values array. The 1st and 3rd entries in each array row represent X values. The 2nd and 4th entries represent the corresponding Y values.

The program then sends the data to the MSChart control's ChartData property. It sets the ChartType to VtChChartType2dXY so the control knows that the array contains both X and Y values.

 
Private Sub Form_Load()
Dim theta_min As Single
Dim theta_max As Single
Dim dtheta As Single
Dim theta As Single
Dim r As Single
Dim values() As Single
Dim i As Integer
Dim num_theta As Integer

    theta_min = 0
    theta_max = 3.14159265
    num_theta = 100
    dtheta = theta_max / (num_theta - 1)
    ReDim values(1 To num_theta, 1 To 4)

    ' Compute the data values.
    Randomize
    theta = theta_min
    For i = 1 To num_theta
        r = Cos(3 * theta)
        values(i, 1) = i
        values(i, 2) = r * Sin(theta) * 10 * (Rnd + 0.5)
        values(i, 3) = 0.66 * i + num_theta / 4
        values(i, 4) = r * Cos(theta * 2) * 10 * (Rnd + _
            0.5) + 10
        theta = theta + dtheta
    Next i

    ' Send the data to the chart.
    Chart1.chartType = VtChChartType2dXY
    Chart1.ColumnCount = num_theta
    Chart1.ChartData = values
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated