XY Chart NET 3 Control Reference
Sample 5: XScaleFactor, YScaleFactor, 2 X-Scales, 2 Y-Scales

This sample demonstrates how to toggle between different scale units.

This chart shows two random profiles, each mapped to their own X & Y scales.  All data entered are stored as the base unit (in this example, seconds for the x-values and inches for the y-values).  Right-click on an x-scale to alternate the display of data between seconds and minutes.  Right-click on a y-scale to alternate the display of data between inches and centimeters.  Snapshots of the resulting chart are included below.

To test this code, the trial or full version of XY Chart NET must be installed on your computer.

  1. Start a new project
  2. Copy the code below directly into the project
  3. On the form, place a new XYChartNET control named XYChartNETCtl1 (default)
  4. Select ContextMenu from the Toolbox and add it to the form; name it mnuX1UnitsList
  5. Add a subitem to mnuX1UnitsList and name it mnuX1Units_sec; set Text to "s", and Checked to True
  6. Add a second subitem to mnuX1UnitsList and name it mnuX1Units_min; set Text to "min"
  7. Select ContextMenu from the Toolbox and add it to the form; name it mnuY1UnitsList
  8. Add a subitem to mnuY1UnitsList and name it mnuY1Units_inch; set Text to "inches", and Checked to True
  9. Add a second subitem to mnuY1UnitsList and name it mnuY1Units_cm; set Text to "cm"
  10. Run the project

 

Sample Code

Private iScaleIndex As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim myTitleFont As New Font("Arial", 16, FontStyle.Italic Or FontStyle.Bold)
   Dim my14Font As New Font("Arial", 14, FontStyle.Bold)
   Dim my10Font As New Font("Arial", 10, FontStyle.Bold)
   Dim ChartData(9, 3) As Double '2 Profiles, 10 samples each
  
   ' Configure XY Chart NET control
   With XyChartNETCtl1
      .NumProfiles = 2
      .NumXScales = 2
      .NumYScales = 2

      ' Init Chart Data for Profile 0 (x-values are in seconds; y-values are in inches)
      ChartData(0, 0) = 0
      ChartData(0, 1) = 0
      ChartData(1, 0) = 1
      ChartData(1, 1) = 1
      ChartData(2, 0) = 2
      ChartData(2, 1) = 2     
      ChartData(3, 0) = 3
      ChartData(3, 1) = 4     
      ChartData(4, 0) = 4     
      ChartData(4, 1) = 8     
      ChartData(5, 0) = 5     
      ChartData(5, 1) = 16     
      ChartData(6, 0) = 6     
      ChartData(6, 1) = 32     
      ChartData(7, 0) = 7     
      ChartData(7, 1) = 64     
      ChartData(8, 0) = 8     
      ChartData(8, 1) = 128     
      ChartData(9, 0) = 9     
      ChartData(9, 1) = 256
     
      ' Init Chart Data for Profile 1 (x-values are in seconds; y-values are in inches)     
      ChartData(0, 2) = 0
      ChartData(0, 3) = 0
      ChartData(1, 2) = 1
      ChartData(1, 3) = 10
      ChartData(2, 2) = 2
      ChartData(2, 3) = 20
      ChartData(3, 2) = 3
      ChartData(3, 3) = 30
      ChartData(4, 2) = 4
      ChartData(4, 3) = 40
      ChartData(5, 2) = 5
      ChartData(5, 3) = 50
      ChartData(6, 2) = 6
      ChartData(6, 3) = 60
      ChartData(7, 2) = 7
      ChartData(7, 3) = 70
      ChartData(8, 2) = 8
      ChartData(8, 3) = 80
      ChartData(9, 2) = 9
      ChartData(9, 3) = 90
           
      ' Format Legend
      .Legend.Visible = True
      .Legend.Position = XYChartNet.XYChartNETCtl.RLPositionOptions.rlRight
      .Legend.BorderVisible = False
      .Legend.YScaleVisible = False

      ' Crosshairs
      .Crosshairs.YCoordInLegend = True
      .Crosshairs.Color = Color.Yellow
      .Crosshairs.Width = XYChartNet.XYChartNETCtl.WidthOptions.woTwoPoint
      .Crosshairs.HorizontalVisible = False
      .Crosshairs.CoordsBackcolor = Color.Yellow

      ' Toolbar and Title
      .Toolbar.BackColor = Color.Lavender
      .Toolbar.Dock = XYChartNet.XYChartNETCtl.PositionOptions.poTop
      .Title.Label = "Sample 5"
      .Title.Position = XYChartNet.XYChartNETCtl.PositionOptions.poLeft
      .Title.Font = myTitleFont
      .Title.Color = Color.Blue

      ' Chart & plot formatting
      .BackColor = Color.Lavender
      .Plot.BackColor = Color.Lavender
      .Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
      .Plot.Border.LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woOnePoint
      .Plot.Border.LineColor = Color.Green

      ' X Axis
      With .XAxis(0)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.Maroon
         End With
         With .Scale
            .Visible = True
            .Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spLeftOrBottom
            .Label = "seconds"
            .LabelColor = Color.Maroon
            .TicksColor = Color.Maroon
            .TicksFont = my14Font
         End With
      End With
      With .XAxis(1)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.DarkBlue
         End With
         With .Scale
            .Visible = True
            .Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spRightOrTop
            .Label = "seconds"
            .LabelColor = Color.DarkBlue
            .TicksColor = Color.DarkBlue
            .TicksFont = my10Font
         End With
      End With

      ' Y Axis
      With .YAxis(0)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.Maroon
         End With
         With .Scale
            .Visible = True
            .Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spLeftOrBottom
            .LabelVertical = "inches"           
            .LabelVerticalColor = Color.Maroon
            .TicksColor = Color.Maroon
            .TicksFont = my14Font
         End With
      End With
      With .YAxis(1)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.DarkBlue
         End With
         With .Scale
            .Visible = True
            .Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spRightOrTop
            .LabelVertical = "inches"           
            .LabelVerticalColor = Color.DarkBlue
            .TicksColor = Color.DarkBlue
            .TicksFont = my10Font
         End With
      End With
           
      ' Format Profile 0
      With .Profile(0)
         .XScale = 0
         .YScale = 0
         .Label = "Profile 0"
         .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
         .LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woThreePoint
         .LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid
         .LineColor = Color.Maroon
         .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
         .NumSamples = 10
      End With

      ' Format Profile 1
      With .Profile(1)
         .XScale = 1
         .YScale = 1
         .Label = "Profile 1"
         .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
         .LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woThreePoint
         .LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid
         .LineColor = Color.DarkBlue
         .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
         .NumSamples = 10
      End With

      ' Assign the data and update the chart
      .ChartData = ChartData
      .Refresh()
     
   End With
End Sub

     
'Resize Event
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
   With XyChartNETCtl1
      .Left = 0
      .Top = 0
      .Width = Me.ClientRectangle.Width
      .Height = Me.ClientRectangle.Height
   End With
End Sub

     
'X-Scale MouseDown Event
Private Sub XyChartNETCtl1_XScaleMouseDown(ByVal Button As System.Windows.Forms.MouseButtons, ByVal Index As Integer, ByVal xPos As Integer, ByVal yPos As Integer) Handles XyChartNETCtl1.XScaleMouseDown
   If Button = MouseButtons.Right Then
      iScaleIndex = Index
      If (XyChartNETCtl1.XAxis(iScaleIndex).Scale.ScaleFactor = 1) Then
          mnuX1Units_sec.Checked = True
          mnuX1Units_min.Checked = False
      Else
          mnuX1Units_sec.Checked = False
          mnuX1Units_min.Checked = True
      End If
      mnuX1UnitsList.Show(XyChartNETCtl1, New Point(xPos, yPos))
   End If
End Sub

     
'Y-Scale MouseDown Event
Private Sub XyChartNETCtl1_YScaleMouseDown(ByVal Button As System.Windows.Forms.MouseButtons, ByVal Index As Integer, ByVal xPos As Integer, ByVal yPos As Integer) Handles XyChartNETCtl1.YScaleMouseDown
   If Button = MouseButtons.Right Then
      iScaleIndex = Index
      If (XyChartNETCtl1.YAxis(iScaleIndex).Scale.ScaleFactor = 1) Then
          mnuY1Units_inch.Checked = True
          mnuY1Units_cm.Checked = False
      Else
          mnuY1Units_inch.Checked = False
          mnuY1Units_cm.Checked = True
     End If
      mnuY1UnitsList.Show(XyChartNETCtl1, New Point(xPos, yPos))
   End If
End Sub
   

'Popup menu events
Private Sub mnuX1Units_sec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuX1Units_sec.Click
   With XyChartNETCtl1
      .XAxis(iScaleIndex).Scale.ScaleFactor = 1     'Since the base unit for the x-values is in seconds
      .XAxis(iScaleIndex).Scale.Label = "seconds"
      .Redraw()  'In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
   End With
End Sub
     
Private Sub mnuX1Units_min_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuX1Units_min.Click
   With XyChartNETCtl1
      .XAxis(iScaleIndex).Scale.ScaleFactor = 1 / 60
      .XAxis(iScaleIndex).Scale.Label = "minutes"
      .Redraw()  'In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
   End With
End Sub
     
Private Sub mnuY1Units_inch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuY1Units_inch.Click
   With XyChartNETCtl1
      .YAxis(iScaleIndex).Scale.ScaleFactor = 1     'Since the base unit for the y-values is in inches
      .YAxis(iScaleIndex).Scale.LabelVertical = "inches"
      .Redraw()  'In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
   End With
End Sub
     
Private Sub mnuY1Units_cm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuY1Units_cm.Click
   With XyChartNETCtl1
      .YAxis(iScaleIndex).Scale.ScaleFactor = 2.54
      .YAxis(iScaleIndex).Scale.LabelVertical = "cm"
      .Redraw()  'In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
   End With
End Sub
// NOTE:  Set the XYChartNET control's Anchor property to 'Top, Bottom, Left, Right'.

private int iScaleIndex;

public Form1()
{
    // Add the following code after the call to InitializeComponent
    const int myNumSamples = 10;
    const int myXYSet = 4;

    Font       myTitleFont = new Font("Arial", 16, FontStyle.Bold | FontStyle.Italic);
    Font       my14Font = new Font("Arial", 14, FontStyle.Bold);
    Font       my10Font = new Font("Arial", 10, FontStyle.Bold);
    double [,] ChartData = new double [myNumSamples, myXYSet];

    XYChartNet.XYChartNETCtl.XSCALEPROP xAxis;
    XYChartNet.XYChartNETCtl.YSCALEPROP yAxis;
    XYChartNet.XYChartNETCtl.C_Profile  profile;

    // Configure XY Chart NET control
    XYChartNETCtl1.NumProfiles = 2;
    XYChartNETCtl1.NumXScales = 2;
    XYChartNETCtl1.NumYScales = 2;

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

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

    // Legend
    XYChartNETCtl1.Legend.Visible = true;

    XYChartNETCtl1.Legend.Position = XYChartNet.XYChartNETCtl.RLPositionOptions.rlRight;
    XYChartNETCtl1.Legend.BorderVisible = false;
    XYChartNETCtl1.Legend.YScaleVisible = false;
           
    // Crosshairs
    XYChartNETCtl1.Crosshairs.YCoordInLegend = true;
    XYChartNETCtl1.Crosshairs.Color = Color.Yellow;
    XYChartNETCtl1.Crosshairs.Width = XYChartNet.XYChartNETCtl.WidthOptions.woTwoPoint;
    XYChartNETCtl1.Crosshairs.CoordsBackcolor = Color.Yellow;
    XYChartNETCtl1.Crosshairs.HorizontalVisible = false;
    XYChartNETCtl1.Crosshairs.VerticalVisible = true;

    // Toolbar and Title
    XYChartNETCtl1.Title.Label = "Sample 5";
    XYChartNETCtl1.Title.Font = myTitleFont;
    XYChartNETCtl1.Title.Color = Color.Blue;
    XYChartNETCtl1.Title.Position = XYChartNet.XYChartNETCtl.PositionOptions.poLeft;
    XYChartNETCtl1.Toolbar.BackColor = Color.Lavender;
    XYChartNETCtl1.Toolbar.Dock = XYChartNet.XYChartNETCtl.PositionOptions.poTop;

    // Chart and plot formatting
    XYChartNETCtl1.BackColor = Color.Lavender;
    XYChartNETCtl1.Plot.BackColor = Color.Lavender;
    XYChartNETCtl1.Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    XYChartNETCtl1.Plot.Border.LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woOnePoint;
    XYChartNETCtl1.Plot.Border.LineColor = Color.Green;

    // X Axis 0 Grid & Scale properties
    xAxis = XYChartNETCtl1.get_XAxis(0);
    xAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    xAxis.Grid.LineColor = Color.Maroon;
    xAxis.Scale.Label = "seconds";
    xAxis.Scale.LabelColor = Color.Maroon;
    xAxis.Scale.TicksColor = Color.Maroon;
    xAxis.Scale.TicksFont = my14Font;
    xAxis.Scale.Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spLeftOrBottom;
    xAxis.Scale.Visible = true;

    // X Axis 1 Grid & Scale properties
    xAxis = XYChartNETCtl1.get_XAxis(1);
    xAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    xAxis.Grid.LineColor = Color.DarkBlue;
    xAxis.Scale.Label = "seconds";
    xAxis.Scale.LabelColor = Color.DarkBlue;
    xAxis.Scale.TicksColor = Color.DarkBlue;
    xAxis.Scale.TicksFont = my10Font;
    xAxis.Scale.Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spRightOrTop;
    xAxis.Scale.Visible = true;

    // Y Axis 0 Grid & Scale properties
    yAxis = XYChartNETCtl1.get_YAxis(0);
    yAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    yAxis.Grid.LineColor = Color.Maroon;
    yAxis.Scale.LabelVertical = "inches";
    yAxis.Scale.LabelVerticalColor = Color.Maroon;
    yAxis.Scale.TicksColor = Color.Maroon;
    yAxis.Scale.TicksFont = my14Font;
    yAxis.Scale.Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spLeftOrBottom;
    yAxis.Scale.Visible = true;

    // Y Axis 1 Grid & Scale properties
    yAxis = XYChartNETCtl1.get_YAxis(1);
    yAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    yAxis.Grid.LineColor = Color.DarkBlue;
    yAxis.Scale.LabelVertical = "inches";
    yAxis.Scale.LabelVerticalColor = Color.DarkBlue;
    yAxis.Scale.TicksColor = Color.DarkBlue;
    yAxis.Scale.TicksFont = my10Font;
    yAxis.Scale.Position = XYChartNet.XYChartNETCtl.ScalePositionOptions.spRightOrTop;
    yAxis.Scale.Visible = true;

    // Profile 0
    profile = XYChartNETCtl1.get_Profile(0);
    profile.XScale = 0;
    profile.YScale = 0;
    profile.Label = "Profile 0";
    profile.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    profile.LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woThreePoint;
    profile.LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid;
    profile.LineColor = Color.Maroon;
    profile.MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone;
    profile.NumSamples = myNumSamples;

    // Profile 1
    profile = XYChartNETCtl1.get_Profile(1);
    profile.XScale = 1;
    profile.YScale = 1;
    profile.Label = "Profile 1";
    profile.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    profile.LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woThreePoint;
    profile.LineStyle = XYChartNet.XYChartNETCtl.StyleOptions.soSolid;
    profile.LineColor = Color.DarkBlue;
    profile.MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone;
    profile.NumSamples = myNumSamples;

    // Assign the data and update the chart
    XYChartNETCtl1.ChartData = ChartData;
    XYChartNETCtl1.Refresh();
}


// X-Scale MouseDown Event
private void XYChartNETCtl1_XScaleMouseDown(System.Windows.Forms.MouseButtons Button, int Index, int xPos, int yPos)
{
    XYChartNet.XYChartNETCtl.XSCALEPROP xAxis;

    if (Button == MouseButtons.Right)
    {
        iScaleIndex = Index;
        xAxis = XYChartNETCtl1.get_XAxis(iScaleIndex);
        if (xAxis.Scale.ScaleFactor == 1)
        {
            mnuX1Units_sec.Checked = true;
            mnuX1Units_min.Checked = false;
        }
        else
        {
            mnuX1Units_sec.Checked = false;
            mnuX1Units_min.Checked = true;
        }
        mnuX1UnitsList.Show(XYChartNETCtl1, new Point(xPos, yPos));
    }
}


// Y-Scale MouseDown Event
private void XYChartNETCtl1_YScaleMouseDown(System.Windows.Forms.MouseButtons Button, int Index, int xPos, int yPos)
{
    XYChartNet.XYChartNETCtl.YSCALEPROP yAxis;

    if (Button == MouseButtons.Right)
    {
        iScaleIndex = Index;
        yAxis = XYChartNETCtl1.get_YAxis(iScaleIndex);
        if (yAxis.Scale.ScaleFactor == 1)
        {
            mnuY1Units_inch.Checked = true;
            mnuY1Units_cm.Checked = false;
        }
        else
        {
            mnuY1Units_inch.Checked = false;
            mnuY1Units_cm.Checked = true;
        }
        mnuY1UnitsList.Show(XYChartNETCtl1, new Point(xPos, yPos));
}


// Popup menu events
private void mnuX1Units_sec_Click(object sender, System.EventArgs e)
{
    XYChartNet.XYChartNETCtl.XSCALEPROP xAxis;

    xAxis = XYChartNETCtl1.get_XAxis(iScaleIndex);
    xAxis.Scale.ScaleFactor = 1;        // Since the base unit for the x-values is in seconds
    xAxis.Scale.Label = "seconds";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1.Redraw();
}

private void mnuX1Units_min_Click(object sender, System.EventArgs e)
{
    XYChartNet.XYChartNETCtl.XSCALEPROP xAxis;

    xAxis = XYChartNETCtl1.get_XAxis(iScaleIndex);
    xAxis.Scale.ScaleFactor = (double) 1 / 60;        // Since the base unit for the x-values is in seconds
    xAxis.Scale.Label = "minutes";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1.Redraw();
}

private void mnuY1Units_inch_Click(object sender, System.EventArgs e)
{
    XYChartNet.XYChartNETCtl.YSCALEPROP yAxis;

    yAxis = XYChartNETCtl1.get_YAxis(iScaleIndex);
    yAxis.Scale.ScaleFactor = 1;        // Since the base unit for the y-values is in inches
    yAxis.Scale.LabelVertical = "inches";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1.Redraw();
}

private void mnuY1Units_cm_Click(object sender, System.EventArgs e)
{
    XYChartNet.XYChartNETCtl.YSCALEPROP yAxis;

    yAxis = XYChartNETCtl1.get_YAxis(iScaleIndex);
    yAxis.Scale.ScaleFactor = 2.54;   
    yAxis.Scale.LabelVertical = "cm";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1.Redraw();
}
// NOTE:  Set the XYChartNET control's Anchor property to 'Top, Bottom, Left, Right'.

private: int iScaleIndex;
       
public Form1()
{
    // Add the following code after the call to InitializeComponent
    const int    myNumSamples = 10;
    const int    myXYSet = 4;

    double                  ChartData __gc[,] = new double __gc[myNumSamples, myXYSet];
    int                     myFontStyle = (int)Drawing::FontStyle::Bold | (int)Drawing::FontStyle::Italic;
    System::Drawing::Font*  myTitleFont = new Drawing::Font("Arial", 16, (Drawing::FontStyle)myFontStyle);
    System::Drawing::Font*  my14Font = new Drawing::Font("Arial", 14, Drawing::FontStyle::Bold);
    System::Drawing::Font*  my10Font = new Drawing::Font("Arial", 10, Drawing::FontStyle::Bold);

    // Configure XY Chart NET control
    XYChartNETCtl1->NumProfiles = 2;
    XYChartNETCtl1->NumXScales = 2;
    XYChartNETCtl1->NumYScales = 2;

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

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

    // Legend
    XYChartNETCtl1->Legend->Visible = true;
    XYChartNETCtl1->Legend->Position = XYChartNETCtl::RLPositionOptions::rlRight;
    XYChartNETCtl1->Legend->BorderVisible = false;
    XYChartNETCtl1->Legend->YScaleVisible = false;

    // Crosshairs
    XYChartNETCtl1->Crosshairs->YCoordInLegend = true;
    XYChartNETCtl1->Crosshairs->Color = Color::Yellow;
    XYChartNETCtl1->Crosshairs->Width = XYChartNETCtl::WidthOptions::woTwoPoint;
    XYChartNETCtl1->Crosshairs->CoordsBackcolor = Color::Yellow;
    XYChartNETCtl1->Crosshairs->HorizontalVisible = false;
    XYChartNETCtl1->Crosshairs->VerticalVisible = true;

    // Toolbar and Title
    XYChartNETCtl1->Title->Label = "Sample 5";
    XYChartNETCtl1->Title->Font = myTitleFont;
    XYChartNETCtl1->Title->Color = Color::Blue;
    XYChartNETCtl1->Title->Position = XYChartNETCtl::PositionOptions::poLeft;
    XYChartNETCtl1->Toolbar->Visible = true;
    XYChartNETCtl1->Toolbar->BackColor = Color::Lavender;
    XYChartNETCtl1->Toolbar->Dock = XYChartNETCtl::PositionOptions::poTop;

    // Chart and plot formatting
    XYChartNETCtl1->BackColor = Color::Lavender;
    XYChartNETCtl1->Plot->BackColor = Color::Lavender;
    XYChartNETCtl1->Plot->Border->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->Plot->Border->LineWidth = XYChartNETCtl::WidthOptions::woOnePoint;
    XYChartNETCtl1->Plot->Border->LineColor = Color::Green;

    // X Axis 0 Grid & Scale properties
    XYChartNETCtl1->get_XAxis(0).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_XAxis(0).Grid->LineColor = Color::Maroon;
    XYChartNETCtl1->get_XAxis(0).Scale->Label = "seconds";
    XYChartNETCtl1->get_XAxis(0).Scale->LabelColor = Color::Maroon;
    XYChartNETCtl1->get_XAxis(0).Scale->TicksColor = Color::Maroon;
    XYChartNETCtl1->get_XAxis(0).Scale->TicksFont = my14Font;
    XYChartNETCtl1->get_XAxis(0).Scale->Position = XYChartNETCtl::ScalePositionOptions::spLeftOrBottom;
    XYChartNETCtl1->get_XAxis(0).Scale->Visible = true;

    // X Axis 1 Grid & Scale properties
    XYChartNETCtl1->get_XAxis(1).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_XAxis(1).Grid->LineColor = Color::DarkBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->Label = "seconds";
    XYChartNETCtl1->get_XAxis(1).Scale->LabelColor = Color::DarkBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->TicksColor = Color::DarkBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->TicksFont = my10Font;
    XYChartNETCtl1->get_XAxis(1).Scale->Position = XYChartNETCtl::ScalePositionOptions::spRightOrTop;
    XYChartNETCtl1->get_XAxis(1).Scale->Visible = true;

    // Y Axis 0 Grid & Scale properties
    XYChartNETCtl1->get_YAxis(0).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_YAxis(0).Grid->LineColor = Color::Maroon;
    XYChartNETCtl1->get_YAxis(0).Scale->LabelVertical = "inches";
    XYChartNETCtl1->get_YAxis(0).Scale->LabelVerticalColor = Color::Maroon;
    XYChartNETCtl1->get_YAxis(0).Scale->TicksColor = Color::Maroon;
    XYChartNETCtl1->get_YAxis(0).Scale->TicksFont = my14Font;
    XYChartNETCtl1->get_YAxis(0).Scale->Position = XYChartNETCtl::ScalePositionOptions::spLeftOrBottom;
    XYChartNETCtl1->get_YAxis(0).Scale->Visible = true;

    // Y Axis 1 Grid & Scale properties
    XYChartNETCtl1->get_YAxis(1).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_YAxis(1).Grid->LineColor = Color::DarkBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->LabelVertical = "inches";
    XYChartNETCtl1->get_YAxis(1).Scale->LabelVerticalColor = Color::DarkBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->TicksColor = Color::DarkBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->TicksFont = my10Font;
    XYChartNETCtl1->get_YAxis(1).Scale->Position = XYChartNETCtl::ScalePositionOptions::spRightOrTop;
    XYChartNETCtl1->get_YAxis(1).Scale->Visible = true;

    // Profile 0
    XYChartNETCtl1->get_Profile(0)->XScale = 0;
    XYChartNETCtl1->get_Profile(0)->YScale = 0;
    XYChartNETCtl1->get_Profile(0)->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_Profile(0)->LineWidth = XYChartNETCtl::WidthOptions::woThreePoint;
    XYChartNETCtl1->get_Profile(0)->LineStyle = XYChartNETCtl::StyleOptions::soSolid;
    XYChartNETCtl1->get_Profile(0)->LineColor = Color::Maroon;
    XYChartNETCtl1->get_Profile(0)->MarkerOption = XYChartNETCtl::LineOptions::loNone;
    XYChartNETCtl1->get_Profile(0)->Label = "Profile 0";
    XYChartNETCtl1->get_Profile(0)->NumSamples = myNumSamples;

    // Profile 1
    XYChartNETCtl1->get_Profile(1)->XScale = 1;
    XYChartNETCtl1->get_Profile(1)->YScale = 1;
    XYChartNETCtl1->get_Profile(1)->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_Profile(1)->LineWidth = XYChartNETCtl::WidthOptions::woThreePoint;
    XYChartNETCtl1->get_Profile(1)->LineStyle = XYChartNETCtl::StyleOptions::soSolid;
    XYChartNETCtl1->get_Profile(1)->LineColor = Color::DarkBlue;
    XYChartNETCtl1->get_Profile(1)->MarkerOption = XYChartNETCtl::LineOptions::loNone;
    XYChartNETCtl1->get_Profile(1)->Label = "Profile 1";
    XYChartNETCtl1->get_Profile(1)->NumSamples = myNumSamples;

    // Assign the data and update the chart
    XYChartNETCtl1->ChartData = ChartData;
    XYChartNETCtl1->Refresh();
}


// X-Scale MouseDown Event
private: System::Void XYChartNETCtl1_XScaleMouseDown(System::Windows::Forms::MouseButtons Button, System::Int32 Index, System::Int32 xPos, System::Int32 yPos)
{
    if (Button == MouseButtons::Right)
    {
        iScaleIndex = Index;
        if (XYChartNETCtl1->get_XAxis(iScaleIndex).Scale->ScaleFactor == 1)
        {
            mnuX1Units_sec->Checked = true;
            mnuX1Units_min->Checked = false;
        }
        else
        {
            mnuX1Units_sec->Checked = false;
            mnuX1Units_min->Checked = true;
        }
        mnuX1UnitsList->Show(XYChartNETCtl1, Point(xPos, yPos));
    }
}


// Y-Scale MouseDown Event
private: System::Void XYChartNETCtl1_YScaleMouseDown(System::Windows::Forms::MouseButtons Button, System::Int32 Index, System::Int32 xPos, System::Int32 yPos)
{
    if (Button == MouseButtons::Right)
    {
        iScaleIndex = Index;
        if (XYChartNETCtl1->get_YAxis(iScaleIndex).Scale->ScaleFactor == 1)
        {
            mnuY1Units_inch->Checked = true;
            mnuY1Units_cm->Checked = false;
        }
        else
        {
            mnuY1Units_inch->Checked = false;
            mnuY1Units_cm->Checked = true;
        }
        mnuY1UnitsList->Show(XYChartNETCtl1, Point(xPos, yPos));
    }
}


// Popup menu events
private: System::Void mnuX1Units_sec_Click(System::Object *  sender, System::EventArgs *  e)
{
    XYChartNETCtl1->get_XAxis(iScaleIndex).Scale->ScaleFactor = 1;        // Since the base unit for the x-values is in seconds
    XYChartNETCtl1->get_XAxis(iScaleIndex).Scale->Label = "seconds";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1->Redraw();
}

private: System::Void mnuX1Units_min_Click(System::Object *  sender, System::EventArgs *  e)
{
    XYChartNETCtl1->get_XAxis(iScaleIndex).Scale->ScaleFactor = (double) 1 / 60;        // Since the base unit for the x-values is in seconds
    XYChartNETCtl1->get_XAxis(iScaleIndex).Scale->Label = "minutes";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1->Redraw();
}

private: System::Void mnuY1Units_inch_Click(System::Object *  sender, System::EventArgs *  e)
{
    XYChartNETCtl1->get_YAxis(iScaleIndex).Scale->ScaleFactor = 1;        // Since the base unit for the y-values is in inches
    XYChartNETCtl1->get_YAxis(iScaleIndex).Scale->LabelVertical = "inches";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1->Redraw();
}

private: System::Void mnuY1Units_cm_Click(System::Object *  sender, System::EventArgs *  e)
{
    XYChartNETCtl1->get_YAxis(iScaleIndex).Scale->ScaleFactor = 2.54;   
    XYChartNETCtl1->get_YAxis(iScaleIndex).Scale->LabelVertical = "cm";

    // In case we are in the zoomed-in state, use Redraw in order to maintain the current min and max values
    XYChartNETCtl1->Redraw();
}

 

 Initial display

 

 

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

 

 


© 2003 - 2013 ControlEng Corporation. All rights reserved.