'
To test this code, the trial or full version of XYChart must be installed
on your computer.
' 1. Start a new standard Visual Basic project
' 2. Copy the code below directly into the project
' 3. On the form, place a new XYChart control named XYChart4Ctl1 (default)
' 4. Save the project
' 5. Right click and "Save Target As..." to download and save
the Data2.txt file in the same folder
as the VB project
' 6. Run the project
Private Sub Form_Load()
' Configure XYChart control
With XYChart4Ctl1
.NumProfiles = 3
.NumYScales = 3
.NumXScales = 1
.Toolbar.Visible = True
.Legend.Visible = True
.Legend.BorderVisible
= False
.Legend.YScaleVisible
= False
.YGrid(1).LineOption =
loCustom
.YGrid(1).LineStyle =
soSolid
.YGrid(1).LineColor =
RGB(190, 190, 190)
.YGrid(2).LineOption =
loNone
.YGrid(3).LineOption =
loNone
.XGrid(1).LineOption =
loCustom
.XGrid(1).LineStyle =
soSolid
.XGrid(1).LineColor =
.YGrid(1).LineColor
.XScale(1).Label = "Time
(s)"
.XScale(1).TicksFont.Color
= vbBlack
.XScale(1).LabelFont.Color
= .XScale(1).TicksFont.Color
.BackColor = RGB(210,
210, 220)
.Plot.BackColor = RGB(255,
255, 255)
.Plot.Border.LineOption
= loCustom
.Plot.Border.LineColor
= RGB(60, 60, 60)
.YScale(1).Label = "m"
.YScale(1).TicksFont.Color
= RGB(255, 0, 0)
.YScale(1).LabelFont.Color
= .YScale(1).TicksFont.Color
.YScale(1).TicksFont.Color
= .YScale(1).TicksFont.Color
.YScale(1).Visible
= True
.YScale(2).Label = "m/s"
.YScale(2).TicksFont.Color
= RGB(0, 0, 255)
.YScale(2).LabelFont.Color
= .YScale(2).TicksFont.Color
.YScale(2).TicksFont.Color
= .YScale(2).TicksFont.Color
.YScale(2).Visible
= True
.YScale(3).Label = "m/s"
& Chr(178)
.YScale(3).TicksFont.Color
= RGB(0, 128, 128)
.YScale(3).LabelFont.Color
= .YScale(3).TicksFont.Color
.YScale(3).TicksFont.Color
= .YScale(3).TicksFont.Color
.YScale(3).Visible
= True
.Profile(1).YScale = 1
.Profile(1).Label = "Position
(m)"
.Profile(1).LineOption
= loCustom
.Profile(1).LineWidth
= woTwoPoint
.Profile(1).LineStyle
= soDot
.Profile(1).MarkerOption
= loNone
.Profile(1).LineColor
= RGB(255, 0, 0)
.Profile(1).NumSamples
= 32
.Profile(2).YScale = 2
.Profile(2).Label = "Velocity
(m/s)"
.Profile(2).LineOption
= loCustom
.Profile(2).LineWidth
= woTwoPoint
.Profile(2).LineStyle
= soDot
.Profile(2).MarkerOption
= loNone
.Profile(2).LineColor
= RGB(0, 0, 255)
.Profile(2).NumSamples
= 32
.Profile(3).YScale = 3
.Profile(3).Label = "Accel
(m/s" & Chr(178) & ")"
.Profile(3).LineOption
= loCustom
.Profile(3).LineWidth
= woTwoPoint
.Profile(3).LineStyle
= soSolid
.Profile(3).MarkerOption
= loNone
.Profile(3).LineColor
= RGB(0, 128, 128)
.Profile(3).NumSamples
= 32
'
Get data from csv file
Dim
Data() As Double
GetDataFromFile
Data, "Data2.txt", 32, 6
.ChartData
= Data
'
Crosshairs
.CrossHairs.Color
= RGB(0, 255, 0)
.CrossHairs.Width
= woTwoPoint
.CrossHairs.YCoordInLegend
= True
.CrossHairs.VerticalVisible
= True
.CrossHairs.HorizontalVisible
= False
.CrossHairs.CoordsBackcolor
= vbYellow
.Refresh
End With
End Sub
' Resize Event
Private Sub Form_Resize()
With XYChart4Ctl1
.Left
= 0
.Top
= 0
.Width
= Me.ScaleWidth
.Height
= Me.ScaleHeight
.Refresh
End With
End Sub
' Get data from csv file
Private Sub GetDataFromFile(ByRef DataArray() As Double, FileName As String,
Rows As Integer, Cols As Integer)
Dim FilePathAndName As String
FilePathAndName = App.Path + "\" + FileName
Dim iFileNumber As Integer
iFileNumber = FreeFile
Open FilePathAndName For Input As #iFileNumber
ReDim DataArray(1 To Rows, 1 To Cols)
Dim Row As Integer, Col As Integer
For Row = 1 To Rows
For Col = 1 To Cols
Input
#iFileNumber, DataArray(Row, Col)
Next Col
Next Row
Close #iFileNumber
End Sub
|