Sample 5 - XScaleFactor, YScaleFactor, 2 X Scales, 2 Y Scales

' 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. Right-click on the form and select Menu Editor

' 5. Create two menu items, mnuX1UnitsList and mnuY1UnitsList

' 6. Set the Visible property for mnuX1UnitsList and mnuY1UnitsList to False

' 7. Create mnuX1Units submenu items for mnuX1UnitsList: 's' (Index=0) and 'min' (Index=1)

' 8. Create mnuY1Units submenu items for mnuY1UnitsList: 'inches' (Index=0) and 'cm' (Index=1)

' 9. Run the project

Private iScaleIndex As Integer

Private Sub Form_Load()
     Dim ChartData(1 To 10, 1 To 4) As Double '2 Profiles, 10 samples each

     ' Configure XYChart control
     With XYChart4Ctl1
          .NumProfiles = 2
          .NumYScales = 2
          .NumXScales = 2

          ' Init Chart Data for Profile 1 (x-values are in seconds; y-values are in inches)
          ChartData(1, 1) = 0
          ChartData(1, 2) = 0
          ChartData(2, 1) = 1
          ChartData(2, 2) = 1
          ChartData(3, 1) = 2
          ChartData(3, 2) = 2
          ChartData(4, 1) = 3
          ChartData(4, 2) = 4
          ChartData(5, 1) = 4
          ChartData(5, 2) = 8
          ChartData(6, 1) = 5
          ChartData(6, 2) = 16
          ChartData(7, 1) = 6
          ChartData(7, 2) = 32
          ChartData(8, 1) = 7
          ChartData(8, 2) = 64
          ChartData(9, 1) = 8
          ChartData(9, 2) = 128
          ChartData(10, 1) = 9
          ChartData(10, 2) = 256

          ' Init Chart Data for Profile 2 (x-values are in seconds; y-values are in inches)
          ChartData(1, 3) = 0
          ChartData(1, 4) = 0
          ChartData(2, 3) = 1
          ChartData(2, 4) = 10
          ChartData(3, 3) = 2
          ChartData(3, 4) = 20
          ChartData(4, 3) = 3
          ChartData(4, 4) = 30
          ChartData(5, 3) = 4
          ChartData(5, 4) = 40
          ChartData(6, 3) = 5
          ChartData(6, 4) = 50
          ChartData(7, 3) = 6
          ChartData(7, 4) = 60
          ChartData(8, 3) = 7
          ChartData(8, 4) = 70
          ChartData(9, 3) = 8
          ChartData(9, 4) = 80
          ChartData(10, 3) = 9
          ChartData(10, 4) = 90

          ' Format Legend
          .Legend.Visible = True
          .Legend.BorderVisible = False
          .Legend.YScaleVisible = False

          ' Crosshairs
          .CrossHairs.YCoordInLegend = True
          .CrossHairs.Color = vbYellow
          .CrossHairs.Width = woTwoPoint
          .CrossHairs.HorizontalVisible = False
          .CrossHairs.CoordsBackcolor = vbYellow

          ' Chart and plot formatting
          .BackColor = RGB(110, 110, 192)
          .Plot.BackColor = .BackColor
          .Plot.Border.LineOption = loCustom
          .Plot.Border.LineWidth = woOnePoint
          .Plot.Border.LineColor = RGB(0, 128, 0)

          ' Gridlines
          .YGrid(1).LineOption = loCustom
          .YGrid(1).LineColor = RGB(128, 0, 64)
          .XGrid(1).LineOption = loCustom
          .XGrid(1).LineColor = .YGrid(1).LineColor
          .YGrid(2).LineOption = loCustom
          .YGrid(2).LineColor = RGB(0, 0, 64)
          .XGrid(2).LineOption = loCustom
          .XGrid(2).LineColor = .YGrid(2).LineColor

          ' X Scale 1
          .XScale(1).Label = "seconds"
          .XScale(1).TicksFont.Color = RGB(128, 0, 64)
          .XScale(1).LabelFont.Color = .XScale(1).TicksFont.Color
          .XScale(1).TicksFont.Bold = True
          .XScale(1).TicksFont.Size = 14
          .XScale(1).Visible = True

          ' X Scale 2
          .XScale(2).Label = "seconds"
          .XScale(2).TicksFont.Color = RGB(0, 0, 64)
          .XScale(2).LabelFont.Color = .XScale(2).TicksFont.Color
          .XScale(2).TicksFont.Bold = True
          .XScale(2).TicksFont.Size = 10
          .XScale(2).Visible = True

          ' Y Scale 1
          .YScale(1).LabelVertical = "inches"
          .YScale(1).TicksFont.Color = RGB(128, 0, 64)
          .YScale(1).LabelVerticalFont.Color = .YScale(1).TicksFont.Color
          .YScale(1).TicksFont.Bold = True
          .YScale(1).TicksFont.Size = 14
          .YScale(1).Visible = True

          ' Y Scale 2
          .YScale(2).LabelVertical = "inches"
          .YScale(2).TicksFont.Color = RGB(0, 0, 64)
          .YScale(2).LabelVerticalFont.Color = .YScale(2).TicksFont.Color
          .YScale(2).TicksFont.Bold = True
          .YScale(2).TicksFont.Size = 10
          .YScale(2).Visible = True

          ' Profile 1
          .Profile(1).YScale = 1
          .Profile(1).XScale = 1
          .Profile(1).LineOption = loCustom
          .Profile(1).LineWidth = woThreePoint
          .Profile(1).LineStyle = soSolid
          .Profile(1).MarkerOption = loNone
          .Profile(1).LineColor = RGB(128, 0, 64)
          .Profile(1).Label = "Profile 1"
          .Profile(1).NumSamples = 10

          ' Profile 2
          .Profile(2).YScale = 2
          .Profile(2).XScale = 2
          .Profile(2).LineOption = loCustom
          .Profile(2).LineWidth = woThreePoint
          .Profile(2).LineStyle = soSolid
          .Profile(2).MarkerOption = loNone
          .Profile(2).LineColor = RGB(0, 0, 64)
          .Profile(2).Label = "Profile 2"
          .Profile(2).NumSamples = 10

          ' Assign the data and update the chart
          .ChartData = ChartData
          .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



Private Sub XYChart4Ctl1_XScaleMouseDown(Button As Integer, Index As Integer, xPos As Single, yPos As Single)
     If Button And vbRightButton Then
          iScaleIndex = Index
          PopupMenu mnuX1UnitsList
     End If
End Sub

Private Sub XYChart4Ctl1_YScaleMouseDown(Button As Integer, Index As Integer, xPos As Single, yPos As Single)
     If Button And vbRightButton Then
          iScaleIndex = Index
          PopupMenu mnuY1UnitsList
     End If
End Sub

Private Sub mnuX1Units_Click(Index As Integer)
     If Index = 0 Then
          'seconds
          XYChart4Ctl1.XScaleFactor(iScaleIndex) = 1     'Since the base unit for the x-values is in seconds
          XYChart4Ctl1.XScale(iScaleIndex).Label = "seconds"
    Else
          'minutes
          XYChart4Ctl1.XScaleFactor(iScaleIndex) = 1 / 60
          XYChart4Ctl1.XScale(iScaleIndex).Label = "minutes"
    End If
     XYChart4Ctl1.Redraw    'In case we are in the zoomed-in state, use Redraw in order to maintain the current
                                        'min and max values

End Sub

Private Sub mnuY1Units_Click(Index As Integer)
     If Index = 0 Then
          'inches
          XYChart4Ctl1.YScaleFactor(iScaleIndex) = 1     'Since the base unit for the y-values is in inches
          XYChart4Ctl1.YScale(iScaleIndex).LabelVertical = "inches"
    Else
          'centimeters
          XYChart4Ctl1.YScaleFactor(iScaleIndex) = 2.54
          XYChart4Ctl1.YScale(iScaleIndex).LabelVertical = "cm"
    End If
     XYChart4Ctl1.Redraw    'In case we are in the zoomed-in state, use Redraw in order to maintain the current
                                        'min and max values

End Sub

Initial display

X-Scale 2 is selected to be displayed in minutes; Y-Scale 1 is selected to be displayed in centimeters