Working with Data > Charting Data Directly From Your Program |
Often it may not be convenient to load chart data from a file. For example, if the data is created from within the program using a mathematical calculation, it makes more sense to read it into the chart directly instead of saving it to a file and then reading it again. Not only can this method be quicker, it can also be quite easy to program.
The following example creates a 2-dimensional array, populates the array with data, and then charts the data:
Sub Main
' Declare the arrays needed to do the calculations
Dim Rates(1 To 2) As Double
Dim Values(1 To 2, 1 To 12) As Double
' Set the number of series and points in the chart
Chart2D1.ChartGroups(1).Data.NumSeries = 2
Chart2D1.ChartGroups(1).Data.NumPoints(1) = 12
Chart2D1.ChartGroups(1).Data.NumPoints(2) = 12
' Set the different rates
Rates(1) = 0.17
Rates(2) = 0.089
' Set the initial values for the first and second series
Values(1, 1) = 200
Values(2, 1) = 200
' Populate the Values arrays with data
For i = 1 To 2
For j = 2 To 12
' Calculate the current value of the investment using the
' following calculation:
Values(i, j) = Values(i, j - 1) * Rates(i) + Values(i, j - 1)
Next j
Next i
' Set the common X values
For i = 1 To 12
Chart2D1.ChartGroups(1).Data.x(1, i) = I
Next i
' Set the Y values
For i = 1 To 2
For j = 1 To 12
Chart2D1.ChartGroups(1).Data.y(i, j) = Values(i, j)
Next j
Next I
End Sub