Use this property to set x/y data point values for all Profiles.
ChartData is an array (rows, columns) of double. The number of rows is
the profile with the maximum NumSamples. The number of
columns is 2 x NumProfiles.
Three
common methods to populate the ChartData
array are:
NOTE: For all methods, the source data must be of proper dimension
specified by:
a) Rows = Profile(x).NumSamples where x is the profile number which
has the greatest number of samples
b) Columns = 2 x NumProfiles.
Example
1: Set ChartData equal to a named range in an Excel file
'wb is the name of an Excel workbook object
'Data1 is a Defined
Name in the Excel file with the same dimensions as ChartData
XYChartCtl1.ChartData = wb.Names("Data1").RefersToRange.Value
XYChartCtl1.Refresh 'Refresh required to re-generate graph with new values
Example
2: Set ChartData equal to an array
Dim arrData(1 To 5, 1 To 8) As Double
XYChartCtl1.NumProfiles = 4
'4
profiles to plot
XYChartCtl1.Profile(1).NumSamples = 5 '5 xy data points for each profile
XYChartCtl1.Profile(2).NumSamples = 5 '5 xy data points for each profile
XYChartCtl1.Profile(3).NumSamples = 5 '5 xy data points for each profile
XYChartCtl1.Profile(4).NumSamples = 5 '5 xy data points for each profile
arrData(1, 1) = 0
arrData(1, 2) = 0
arrData(2, 1) = -0.1
arrData(2, 2) = -0.105
arrData(3, 1) = -0.2
arrData(3, 2) = -0.222
arrData(4, 1) = -0.3
arrData(4, 2) = -0.356
arrData(5, 1) = -0.4
arrData(5, 2) = -0.435
arrData(1, 3) = 0
arrData(1, 4) = 0
arrData(2, 3) = -0.02
arrData(2, 4) = -0.02
arrData(3, 3) = -0.04
arrData(3, 4) = -0.05
arrData(4, 3) = -0.05
arrData(4, 4) = -0.06
arrData(5, 3) = -0.075
arrData(5, 4) = -0.0864
arrData(1, 5) = 0.1
arrData(1, 6) = 0
arrData(2, 5) = 0.14
arrData(2, 6) = 0.1
arrData(3, 5) = 0.2
arrData(3, 6) = 0.2
arrData(4, 5) = 0.16
arrData(4, 6) = 0.16
arrData(5, 5) = 0.3
arrData(5, 6) = 0.3
arrData(1, 7) = 0
arrData(1, 8) = 0.01
arrData(2, 7) = 0.01
arrData(2, 8) = 0.05
arrData(3, 7) = 0.05
arrData(3, 8) = 0.03
arrData(4, 7) = 0.03
arrData(4, 8) = 0.08
arrData(5, 7) = 0.08
arrData(5, 8) = 0.075
XYChartCtl1.ChartData = arrData
XYChartCtl1.Refresh 'Refresh required to re-generate graph with new values
Example
3: Read
data from a CSV text file into an array, and then set ChartData equal to the
array
' Read data from a
CSV file and populate DataArray
Dim FilePathAndName As String
' NOTE: File path below assumes source file is in the same folder as the
application
FilePathAndName = App.Path + "\" + FileName
Dim iFileNumber As Integer
iFileNumber = FreeFile
Open FilePathAndName For Input As #iFileNumber
With XYChartCtl1
'
Populate array
Dim Row As Integer, Col As Integer
ReDim DataArray(1 To .Profile(1).NumSamples, 1 To
2*.NumProfiles) 'Assume all profiles have the same number
of samples as Profile 1
For Row = 1 To .Profile(1).NumSamples
For Col = 1 To 2*.NumProfiles
Input
#iFileNumber, DataArray(Row, Col)
Next Col
Next Row
Close #iFileNumber
.ChartData = DataArray
.Refresh 'Refresh required to re-generate graph with new values
End With
See
Also