XY Chart NET 3 Control Reference
Sample 6: Bar Charting

This sample demonstrates how to chart profile data using the bar charting feature.

This chart shows two random profiles, each set to use the Bar ChartFeatureType.  The first profile displays its datapoints as vertical bars using y=0 as its reference line.  The second profile displays its datapoints as vertical bars using y=100 as its reference line.  A snapshot of the resulting chart is 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 i As Short
        Dim ChartData(,) As Double

        With XyChartNETCtl1
            .NumProfiles = 2
            .NumYScales = 1
            .NumXScales = 1

            .Toolbar.BackColor = Me.BackColor
            .Toolbar.Visible = True

            .BackColor = Color.Lavender

            .Plot.BackColor = Color.Transparent
            .Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone

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

            With .Gradient
                .GradientOption = XYChartNet.XYChartNETCtl.GradientOptions.goCustom
                .Orientation = XYChartNet.XYChartNETCtl.OrientationOptions.ooVertical
                .StartColor = Color.Lavender
                .EndColor = Color.LightSteelBlue
            End With

            With .Legend
                .Visible = True
                .BorderVisible = False
                .YScaleVisible = False
            End With

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

            With .YAxis(0)
                With .Grid
                    .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
                    .LineColor = Color.Green
                End With
                With .Scale
                    .ForceZeroDisplay = True
                    .Label = ""
                    .TicksColor = Color.Green
                    .LabelColor = Color.Green
                    .Visible = True
                End With
            End With

            With .XAxis(0)
                With .Grid
                    .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom
                    .LineColor = Color.Green
                End With
                With .Scale
                    .ForceZeroDisplay = True
                    .Label = ""
                    .TicksColor = Color.Green
                    .LabelColor = Color.Green
                    .Visible = True
                End With
            End With

            ' Profile 1
            With .Profile(0)
                .YScale = 0
                .XScale = 0
                .NumSamples = 15
                .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
                .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
                .Label = "Profile 0"

                .ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfBar
                .BarWidth = 0.5
                .BarReference = 0
                .BarBorderColor = Color.Maroon
                .BarFillColor = Color.LightSalmon
            End With

            ' Profile 2
            With .Profile(1)
                .YScale = 0
                .XScale = 0
                .NumSamples = 15
                .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
                .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone
                .Label = "Profile 1"

                .ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfBar
                .BarWidth = 0.5
                .BarReference = 100
                .BarBorderColor = Color.DarkBlue
                .BarFillColor = Color.Cyan
            End With

            ' Populate array, then feed into XYChartNET.ChartData
            ReDim ChartData(.Profile(0).NumSamples - 1, 2 * .NumProfiles - 1)
            For i = 0 To .Profile(0).NumSamples - 1
                ChartData(i, 0) = (i + 1) * 1
                ChartData(i, 1) = 70 * Rnd()

                ChartData(i, 2) = ChartData(i, 0)
                ChartData(i, 3) = 70 * Rnd() + 75
            Next i

            .ChartData = ChartData
            .Refresh()

        End With

    End Sub
               
               

 

 Display

 

 


© 2003 - 2013 ControlEng Corporation. All rights reserved.