XY Chart NET 3 Control Reference
Sample 4: 2 X-Scales, 2 Y-Scales, Y-Stacking, No Scrollbars

This sample demonstrates how to generate multiple plots (y-stacks).

This chart shows two random profiles, each mapped to their own X & Y scales.  The y-scales are stacked vertically.  Also, the scrollbars are not visible when zoomed in.  To scroll the zoomed in chart, use the toolbar Pan feature, or click and drag each scale individually.  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. Run the project

 

Sample Code

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 i As Integer
   Dim ChartData(,) As Double

   ' Configure XY Chart NET control
   With XyChartNETCtl1
      .NumProfiles = 2
      .NumXScales = 2
      .NumYScales = 2

      .Title.Label = "Sample 4"
      .Title.Font = myTitleFont
      .Title.Color = Color.White

      ' Y Stacking
      .YStacking = True
      .NumYStacks = 2
      .YStack(0).HeightPercentage = 70
      .YStack(1).HeightPercentage = 30
      .YStack(0).NumYScales = 1
      .YStack(1).NumYScales = 1

      ' Toolbar
      .Toolbar.Visible = True
      .Toolbar.BackColor = Color.LightBlue

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

      ' Scrollbars
      .Scrollbars.HorizontalVisible = False
      .Scrollbars.VerticalVisible = False

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

      ' X Axis
      With .XAxis(0)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.Maroon
         End With
         With .Scale
            .Visible = True
            .Label = ""
            .LabelColor = Color.Maroon
            .TicksColor = Color.Maroon
            .TicksFont = my14Font
         End With
      End With
      With .XAxis(1)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.MidnightBlue
         End With
         With .Scale
            .Visible = True
            .Label = ""
            .LabelColor = Color.MidnightBlue
            .TicksColor = Color.MidnightBlue
            .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
            .Label = ""
            .LabelColor = Color.Maroon
            .TicksColor = Color.Maroon
            .TicksFont = my14Font
            .ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual
            .ScaleManualMin = 0
            .ScaleManualMax = 100
         End With
      End With
      With .YAxis(1)
         With .Grid
            .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
            .LineColor = Color.MidnightBlue
         End With
         With .Scale
            .Visible = True
            .Label = ""
            .LabelColor = Color.MidnightBlue
            .TicksColor = Color.MidnightBlue
            .TicksFont = my10Font
            .ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual
            .ScaleManualMin = 0
            .ScaleManualMax = 500
         End With
      End With
           
      ' Chart & plot formatting
      .BackColor = Color.LightBlue
      .Plot.BackColor = Color.LightBlue
      .Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone

      ' 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 = 30
      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.MidnightBlue
         .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
         .NumSamples = 30
      End With

      ' Create random chart data, then feed into XYChartNET
      ReDim ChartData(.Profile(0).NumSamples - 1, 2 * .NumProfiles - 1)
      For i = 0 To .Profile(0).NumSamples - 1
         ' Profile 0
         ChartData(i, 0) = i * 1
         ChartData(i, 1) = 70 * Rnd() + 20

         ' Profile 1
         ChartData(i, 2) = i * 25
         ChartData(i, 3) = 450 * Rnd()
      Next i
      .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
// NOTE:  Set the XYChartNET control's Anchor property to 'Top, Bottom, Left, Right'.
// Add the following code after the call to InitializeComponent in public Form1()

    const int myNumSamples = 30;
    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;
    XYChartNet.XYChartNETCtl.C_YStack   yStack;

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

    XYChartNETCtl1.BackColor = Color.LightBlue;

    XYChartNETCtl1.Title.Label = "Sample 4";
    XYChartNETCtl1.Title.Font = myTitleFont;
    XYChartNETCtl1.Title.Color = Color.White;

    // Y Stacking
    XYChartNETCtl1.YStacking = true;
    XYChartNETCtl1.NumYStacks = 2;
    // Y Stack 0
    yStack = XYChartNETCtl1.get_YStack(0);
    yStack.HeightPercentage = 70;
    yStack.NumYScales = 1;
    // Y Stack 1
    yStack = XYChartNETCtl1.get_YStack(1);
    yStack.HeightPercentage = 30;
    yStack.NumYScales = 1;

    // Toolbar
    XYChartNETCtl1.Toolbar.Visible = true;
    XYChartNETCtl1.Toolbar.BackColor = Color.LightBlue;

    // Legend
    XYChartNETCtl1.Legend.Visible = true;
    XYChartNETCtl1.Legend.BorderVisible = false;
    XYChartNETCtl1.Legend.YScaleVisible = false;
       
    // Scrollbars
    XYChartNETCtl1.Scrollbars.HorizontalVisible = false;
    XYChartNETCtl1.Scrollbars.VerticalVisible = 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;

    // Plot formatting
    XYChartNETCtl1.Plot.BackColor = Color.LightBlue;
    XYChartNETCtl1.Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone;

    // 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 = "";
    xAxis.Scale.LabelColor = Color.Maroon;
    xAxis.Scale.TicksColor = Color.Maroon;
    xAxis.Scale.TicksFont = my14Font;

    // X Axis 1 Grid & Scale properties
    xAxis = XYChartNETCtl1.get_XAxis(1);
    xAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    xAxis.Grid.LineColor = Color.MidnightBlue;
    xAxis.Scale.Label = "";
    xAxis.Scale.LabelColor = Color.MidnightBlue;
    xAxis.Scale.TicksColor = Color.MidnightBlue;
    xAxis.Scale.TicksFont = my10Font;

    // 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.Label = "";
    yAxis.Scale.LabelColor = Color.Maroon;
    yAxis.Scale.TicksColor = Color.Maroon;
    yAxis.Scale.TicksFont = my14Font;
    yAxis.Scale.ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual;
    yAxis.Scale.ScaleManualMin = 0;
    yAxis.Scale.ScaleManualMax = 100;

    // Y Axis 1 Grid & Scale properties
    yAxis = XYChartNETCtl1.get_YAxis(1);
    yAxis.Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom;
    yAxis.Grid.LineColor = Color.MidnightBlue;
    yAxis.Scale.Label = "";
    yAxis.Scale.LabelColor = Color.MidnightBlue;
    yAxis.Scale.TicksColor = Color.MidnightBlue;
    yAxis.Scale.TicksFont = my10Font;
    yAxis.Scale.ScaleMode = XYChartNet.XYChartNETCtl.ScaleModes.smManual;
    yAxis.Scale.ScaleManualMin = 0;
    yAxis.Scale.ScaleManualMax = 500;

    // 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.MidnightBlue;
    profile.MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone;
    profile.NumSamples = myNumSamples;

    // Create random chart data, then feed into XYChartNET
    Random rnd = new Random();
    for (int i = 0; i < myNumSamples; i++)
    {
       // Profile 0
       ChartData[i, 0] = i * 1;
       ChartData[i, 1] = 70 * rnd.NextDouble() + 20;

       // Profile 1
       ChartData[i, 2] = i * 25;
       ChartData[i, 3] = 450 * rnd.NextDouble();
    }
    XYChartNETCtl1.ChartData = ChartData;

    XYChartNETCtl1.Refresh();
// NOTE:  Set the XYChartNET control's Anchor property to 'Top, Bottom, Left, Right'.
// Add the following code after the call to InitializeComponent in public Form1()

    const int    myNumSamples = 30;
    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;

    XYChartNETCtl1->BackColor = Color::LightBlue;

    XYChartNETCtl1->Title->Label = "Sample 4";
    XYChartNETCtl1->Title->Font = myTitleFont;
    XYChartNETCtl1->Title->Color = Color::White;

    // Y Stacking
    XYChartNETCtl1->YStacking = true;
    XYChartNETCtl1->NumYStacks = 2;
    XYChartNETCtl1->get_YStack(0)->HeightPercentage = 70;
    XYChartNETCtl1->get_YStack(0)->NumYScales = 1;
    XYChartNETCtl1->get_YStack(1)->HeightPercentage = 30;
    XYChartNETCtl1->get_YStack(1)->NumYScales = 1;

    // Toolbar
    XYChartNETCtl1->Toolbar->Visible = true;
    XYChartNETCtl1->Toolbar->BackColor = Color::LightBlue;

    // Legend
    XYChartNETCtl1->Legend->Visible = true;
    XYChartNETCtl1->Legend->BorderVisible = false;
    XYChartNETCtl1->Legend->YScaleVisible = false;

    // Scrollbars
    XYChartNETCtl1->Scrollbars->HorizontalVisible = false;
    XYChartNETCtl1->Scrollbars->VerticalVisible = 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;

    // Plot formatting
    XYChartNETCtl1->Plot->BackColor = Color::LightBlue;
    XYChartNETCtl1->Plot->Border->LineOption = XYChartNETCtl::LineOptions::loNone;

    // 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 = "";
    XYChartNETCtl1->get_XAxis(0).Scale->LabelColor = Color::Maroon;
    XYChartNETCtl1->get_XAxis(0).Scale->TicksColor = Color::Maroon;
    XYChartNETCtl1->get_XAxis(0).Scale->TicksFont = my14Font;

    // X Axis 1 Grid & Scale properties
    XYChartNETCtl1->get_XAxis(1).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_XAxis(1).Grid->LineColor = Color::MidnightBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->Label = "";
    XYChartNETCtl1->get_XAxis(1).Scale->LabelColor = Color::MidnightBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->TicksColor = Color::MidnightBlue;
    XYChartNETCtl1->get_XAxis(1).Scale->TicksFont = my10Font;

    // 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->Label = "";
    XYChartNETCtl1->get_YAxis(0).Scale->LabelColor = Color::Maroon;
    XYChartNETCtl1->get_YAxis(0).Scale->TicksColor = Color::Maroon;
    XYChartNETCtl1->get_YAxis(0).Scale->TicksFont = my14Font;
    XYChartNETCtl1->get_YAxis(0).Scale->ScaleMode = XYChartNETCtl::ScaleModes::smManual;
    XYChartNETCtl1->get_YAxis(0).Scale->ScaleManualMin = 0;
    XYChartNETCtl1->get_YAxis(0).Scale->ScaleManualMax = 100;

    // Y Axis 1 Grid & Scale properties
    XYChartNETCtl1->get_YAxis(1).Grid->LineOption = XYChartNETCtl::LineOptions::loCustom;
    XYChartNETCtl1->get_YAxis(1).Grid->LineColor = Color::MidnightBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->Label = "";
    XYChartNETCtl1->get_YAxis(1).Scale->LabelColor = Color::MidnightBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->TicksColor = Color::MidnightBlue;
    XYChartNETCtl1->get_YAxis(1).Scale->TicksFont = my10Font;
    XYChartNETCtl1->get_YAxis(1).Scale->ScaleMode = XYChartNETCtl::ScaleModes::smManual;
    XYChartNETCtl1->get_YAxis(1).Scale->ScaleManualMin = 0;
    XYChartNETCtl1->get_YAxis(1).Scale->ScaleManualMax = 500;

    // 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::MidnightBlue;
    XYChartNETCtl1->get_Profile(1)->MarkerOption = XYChartNETCtl::LineOptions::loNone;
    XYChartNETCtl1->get_Profile(1)->Label = "Profile 1";
    XYChartNETCtl1->get_Profile(1)->NumSamples = myNumSamples;

    // Create random chart data, then feed into XYChartNET
    for (int i = 0; i < myNumSamples; i++)
    {
        // Profile 0
        ChartData[i, 0] = i * 1;
        ChartData[i, 1] = 70 * rnd->NextDouble() + 20;

        // Profile 1
        ChartData[i, 2] = i * 25;
        ChartData[i, 3] = 450 * rnd->NextDouble();
    }
    XYChartNETCtl1->ChartData = ChartData;

    XYChartNETCtl1->Refresh();

 

 

 

 

 


© 2003 - 2013 ControlEng Corporation. All rights reserved.