XY Chart NET 3 Control Reference > Samples > Sample 8: Recession Profile |
This sample demonstrates a basic economic chart showing recession periods.
This chart displays three profiles, one of which shows the recession periods. The recession profile is configured to use the automatic mode to define the start and end values for each recession period. A snapshots 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.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim DataArray(,) As Double Dim DataOttawa(,) As Double Dim DataToronto(,) As Double Dim dDate As DateTime = New DateTime(1980, 1, 1) Dim myFont As New Font("Arial", 12, FontStyle.Bold) Dim myFont2 As New Font("Arial", 10, FontStyle.Bold) ' Define the shaded periods, i.e. start and end dates, for the Recession profile ReDim DataArray(7, 1) DataArray(0, 0) = dDate.ToOADate DataArray(1, 0) = dDate.AddMonths(6).ToOADate DataArray(2, 0) = dDate.AddMonths(18).ToOADate DataArray(3, 0) = dDate.AddMonths(34).ToOADate DataArray(4, 0) = dDate.AddMonths(126).ToOADate DataArray(5, 0) = dDate.AddMonths(134).ToOADate DataArray(6, 0) = dDate.AddMonths(262).ToOADate DataArray(7, 0) = dDate.AddMonths(274).ToOADate ' Data for Profile 0 - Ottawa data ReDim DataOttawa(26, 1) DataOttawa(0, 0) = dDate.ToOADate DataOttawa(0, 1) = 62748 DataOttawa(1, 0) = dDate.AddMonths(12).ToOADate DataOttawa(1, 1) = 64896 DataOttawa(2, 0) = dDate.AddMonths(24).ToOADate DataOttawa(2, 1) = 71080 DataOttawa(3, 0) = dDate.AddMonths(36).ToOADate DataOttawa(3, 1) = 86245 DataOttawa(4, 0) = dDate.AddMonths(48).ToOADate DataOttawa(4, 1) = 102084 DataOttawa(5, 0) = dDate.AddMonths(60).ToOADate DataOttawa(5, 1) = 107306 DataOttawa(6, 0) = dDate.AddMonths(72).ToOADate DataOttawa(6, 1) = 111643 DataOttawa(7, 0) = dDate.AddMonths(84).ToOADate DataOttawa(7, 1) = 119612 DataOttawa(8, 0) = dDate.AddMonths(96).ToOADate DataOttawa(8, 1) = 128434 DataOttawa(9, 0) = dDate.AddMonths(108).ToOADate DataOttawa(9, 1) = 137455 DataOttawa(10, 0) = dDate.AddMonths(120).ToOADate DataOttawa(10, 1) = 141438 DataOttawa(11, 0) = dDate.AddMonths(132).ToOADate DataOttawa(11, 1) = 143361 DataOttawa(12, 0) = dDate.AddMonths(144).ToOADate DataOttawa(12, 1) = 143868 DataOttawa(13, 0) = dDate.AddMonths(156).ToOADate DataOttawa(13, 1) = 148129 DataOttawa(14, 0) = dDate.AddMonths(168).ToOADate DataOttawa(14, 1) = 147543 DataOttawa(15, 0) = dDate.AddMonths(180).ToOADate DataOttawa(15, 1) = 143193 DataOttawa(16, 0) = dDate.AddMonths(192).ToOADate DataOttawa(16, 1) = 140534 DataOttawa(17, 0) = dDate.AddMonths(204).ToOADate DataOttawa(17, 1) = 143873 DataOttawa(18, 0) = dDate.AddMonths(216).ToOADate DataOttawa(18, 1) = 143953 DataOttawa(19, 0) = dDate.AddMonths(228).ToOADate DataOttawa(19, 1) = 149650 DataOttawa(20, 0) = dDate.AddMonths(240).ToOADate DataOttawa(20, 1) = 159511 DataOttawa(21, 0) = dDate.AddMonths(252).ToOADate DataOttawa(21, 1) = 175971 DataOttawa(22, 0) = dDate.AddMonths(264).ToOADate DataOttawa(22, 1) = 200711 DataOttawa(23, 0) = dDate.AddMonths(276).ToOADate DataOttawa(23, 1) = 218692 DataOttawa(24, 0) = dDate.AddMonths(288).ToOADate DataOttawa(24, 1) = 235678 DataOttawa(25, 0) = dDate.AddMonths(300).ToOADate DataOttawa(25, 1) = 244531 DataOttawa(26, 0) = dDate.AddMonths(312).ToOADate DataOttawa(26, 1) = 255889 ' Data for Profile 1 - Toronto data ReDim DataToronto(16, 1) DataToronto(0, 0) = dDate.ToOADate DataToronto(0, 1) = 75000 DataToronto(1, 0) = dDate.AddMonths(12).ToOADate DataToronto(1, 1) = 90203 DataToronto(2, 0) = dDate.AddMonths(60).ToOADate DataToronto(2, 1) = 109000 DataToronto(3, 0) = dDate.AddMonths(108).ToOADate DataToronto(3, 1) = 273000 DataToronto(4, 0) = dDate.AddMonths(120).ToOADate DataToronto(4, 1) = 235983 DataToronto(5, 0) = dDate.AddMonths(180).ToOADate DataToronto(5, 1) = 203028 DataToronto(6, 0) = dDate.AddMonths(192).ToOADate DataToronto(6, 1) = 198150 DataToronto(7, 0) = dDate.AddMonths(204).ToOADate DataToronto(7, 1) = 211307 DataToronto(8, 0) = dDate.AddMonths(216).ToOADate DataToronto(8, 1) = 216815 DataToronto(9, 0) = dDate.AddMonths(228).ToOADate DataToronto(9, 1) = 228372 DataToronto(10, 0) = dDate.AddMonths(240).ToOADate DataToronto(10, 1) = 243255 DataToronto(11, 0) = dDate.AddMonths(252).ToOADate DataToronto(11, 1) = 251508 DataToronto(12, 0) = dDate.AddMonths(264).ToOADate DataToronto(12, 1) = 275371 DataToronto(13, 0) = dDate.AddMonths(276).ToOADate DataToronto(13, 1) = 293067 DataToronto(14, 0) = dDate.AddMonths(288).ToOADate DataToronto(14, 1) = 315231 DataToronto(15, 0) = dDate.AddMonths(300).ToOADate DataToronto(15, 1) = 335907 DataToronto(16, 0) = dDate.AddMonths(312).ToOADate DataToronto(16, 1) = 351941 ' Configure XYChart control With XyChartNETCtl1 .NumProfiles = 3 .NumXScales = 1 .NumYScales = 1 With .Title .Label = "Home Sales" .Font = myFont End With With .Toolbar .BackColor = Color.AliceBlue End With With .Gradient .GradientOption = XYChartNet.XYChartNETCtl.GradientOptions.goCustom .StartColor = Color.AliceBlue .EndColor = Color.SteelBlue .Orientation = XYChartNet.XYChartNETCtl.OrientationOptions.ooVertical End With With .Plot.Border .LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woOnePoint .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom .LineColor = Color.Black End With ' Format grid lines With .XAxis(0).Grid .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .LineColor = Color.Green End With With .YAxis(0).Grid .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .LineColor = Color.Green End With ' X Scale With .XAxis(0).Scale .LabelColor = Color.Black .TicksColor = Color.Black .FormatStyle = XYChartNet.XYChartNETCtl.FormatStyles.fsDateTime .DateTimeFormat = "yy" .Label = "" End With ' Y Scale 0 With .YAxis(0).Scale .Visible = True .LabelColor = Color.Black .TicksColor = Color.Black .LabelVertical = "Average Sales Price" .LabelVerticalFont = myFont2 End With ' Format Profile 0 With .Profile(0) .Label = "Recession" .YScale = 0 .NumSamples = 8 .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfRecession .FillEnabled = True .FillColor = Color.Red .RecessionLimitsMode = XYChartNet.XYChartNETCtl.RecessionModes.rmAuto .DisplayInLegend = False End With ' Format Profile 1 With .Profile(1) .Label = "Ottawa" .YScale = 0 .NumSamples = 27 .LineColor = Color.Blue .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .DisplayInLegend = True End With ' Format Profile 2 With .Profile(2) .Label = "Toronto" .YScale = 0 .NumSamples = 17 .LineColor = Color.Green .MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone .DisplayInLegend = True End With ' Feed the data for each Profile .ProfileData(0) = DataArray .ProfileData(1) = DataOttawa .ProfileData(2) = DataToronto .Refresh() End With End Sub
public Form1() { // Add the following code after the call to InitializeComponent double [,] DataArray = new double [8, 2]; double [,] DataOttawa = new double [27, 2]; double [,] DataToronto = new double [17, 2]; Font myFont = new Font("Arial", 12, FontStyle.Bold); Font myFont2 = new Font("Arial", 10, FontStyle.Bold); DateTime dDate = new DateTime(1980, 1, 1); // Define the shaded periods, i.e. start and end dates, for the Recession profile DataArray[0, 0] = dDate.ToOADate(); DataArray[1, 0] = dDate.AddMonths(6).ToOADate(); DataArray[2, 0] = dDate.AddMonths(18).ToOADate(); DataArray[3, 0] = dDate.AddMonths(34).ToOADate(); DataArray[4, 0] = dDate.AddMonths(126).ToOADate(); DataArray[5, 0] = dDate.AddMonths(134).ToOADate(); DataArray[6, 0] = dDate.AddMonths(262).ToOADate(); DataArray[7, 0] = dDate.AddMonths(274).ToOADate(); // Data for Profile 0 - Ottawa data DataOttawa[0, 0] = dDate.ToOADate(); DataOttawa[0, 1] = 62748; DataOttawa[1, 0] = dDate.AddMonths(12).ToOADate(); DataOttawa[1, 1] = 64896; DataOttawa[2, 0] = dDate.AddMonths(24).ToOADate(); DataOttawa[2, 1] = 71080; DataOttawa[3, 0] = dDate.AddMonths(36).ToOADate(); DataOttawa[3, 1] = 86245; DataOttawa[4, 0] = dDate.AddMonths(48).ToOADate(); DataOttawa[4, 1] = 102084; DataOttawa[5, 0] = dDate.AddMonths(60).ToOADate(); DataOttawa[5, 1] = 107306; DataOttawa[6, 0] = dDate.AddMonths(72).ToOADate(); DataOttawa[6, 1] = 111643; DataOttawa[7, 0] = dDate.AddMonths(84).ToOADate(); DataOttawa[7, 1] = 119612; DataOttawa[8, 0] = dDate.AddMonths(96).ToOADate(); DataOttawa[8, 1] = 128434; DataOttawa[9, 0] = dDate.AddMonths(108).ToOADate(); DataOttawa[9, 1] = 137455; DataOttawa[10, 0] = dDate.AddMonths(120).ToOADate(); DataOttawa[10, 1] = 141438; DataOttawa[11, 0] = dDate.AddMonths(132).ToOADate(); DataOttawa[11, 1] = 143361; DataOttawa[12, 0] = dDate.AddMonths(144).ToOADate(); DataOttawa[12, 1] = 143868; DataOttawa[13, 0] = dDate.AddMonths(156).ToOADate(); DataOttawa[13, 1] = 148129; DataOttawa[14, 0] = dDate.AddMonths(168).ToOADate(); DataOttawa[14, 1] = 147543; DataOttawa[15, 0] = dDate.AddMonths(180).ToOADate(); DataOttawa[15, 1] = 143193; DataOttawa[16, 0] = dDate.AddMonths(192).ToOADate(); DataOttawa[16, 1] = 140534; DataOttawa[17, 0] = dDate.AddMonths(204).ToOADate(); DataOttawa[17, 1] = 143873; DataOttawa[18, 0] = dDate.AddMonths(216).ToOADate(); DataOttawa[18, 1] = 143953; DataOttawa[19, 0] = dDate.AddMonths(228).ToOADate(); DataOttawa[19, 1] = 149650; DataOttawa[20, 0] = dDate.AddMonths(240).ToOADate(); DataOttawa[20, 1] = 159511; DataOttawa[21, 0] = dDate.AddMonths(252).ToOADate(); DataOttawa[21, 1] = 175971; DataOttawa[22, 0] = dDate.AddMonths(264).ToOADate(); DataOttawa[22, 1] = 200711; DataOttawa[23, 0] = dDate.AddMonths(276).ToOADate(); DataOttawa[23, 1] = 218692; DataOttawa[24, 0] = dDate.AddMonths(288).ToOADate(); DataOttawa[24, 1] = 235678; DataOttawa[25, 0] = dDate.AddMonths(300).ToOADate(); DataOttawa[25, 1] = 244531; DataOttawa[26, 0] = dDate.AddMonths(312).ToOADate(); DataOttawa[26, 1] = 255889; // Data for Profile 1 - Toronto data DataToronto[0, 0] = dDate.ToOADate(); DataToronto[0, 1] = 75000; DataToronto[1, 0] = dDate.AddMonths(12).ToOADate(); DataToronto[1, 1] = 90203; DataToronto[2, 0] = dDate.AddMonths(60).ToOADate(); DataToronto[2, 1] = 109000; DataToronto[3, 0] = dDate.AddMonths(108).ToOADate(); DataToronto[3, 1] = 273000; DataToronto[4, 0] = dDate.AddMonths(120).ToOADate(); DataToronto[4, 1] = 235983; DataToronto[5, 0] = dDate.AddMonths(180).ToOADate(); DataToronto[5, 1] = 203028; DataToronto[6, 0] = dDate.AddMonths(192).ToOADate(); DataToronto[6, 1] = 198150; DataToronto[7, 0] = dDate.AddMonths(204).ToOADate(); DataToronto[7, 1] = 211307; DataToronto[8, 0] = dDate.AddMonths(216).ToOADate(); DataToronto[8, 1] = 216815; DataToronto[9, 0] = dDate.AddMonths(228).ToOADate(); DataToronto[9, 1] = 228372; DataToronto[10, 0] = dDate.AddMonths(240).ToOADate(); DataToronto[10, 1] = 243255; DataToronto[11, 0] = dDate.AddMonths(252).ToOADate(); DataToronto[11, 1] = 251508; DataToronto[12, 0] = dDate.AddMonths(264).ToOADate(); DataToronto[12, 1] = 275371; DataToronto[13, 0] = dDate.AddMonths(276).ToOADate(); DataToronto[13, 1] = 293067; DataToronto[14, 0] = dDate.AddMonths(288).ToOADate(); DataToronto[14, 1] = 315231; DataToronto[15, 0] = dDate.AddMonths(300).ToOADate(); DataToronto[15, 1] = 335907; DataToronto[16, 0] = dDate.AddMonths(312).ToOADate(); DataToronto[16, 1] = 351941; // Configure XYChart control XyChartNETCtl1.NumProfiles = 3; XyChartNETCtl1.NumXScales = 1; XyChartNETCtl1.NumYScales = 1; XyChartNETCtl1.Title.Label = "Home Sales"; XyChartNETCtl1.Title.Font = myFont; XyChartNETCtl1.Toolbar.BackColor = Color.AliceBlue; XyChartNETCtl1.Gradient.GradientOption = XYChartNet.XYChartNETCtl.GradientOptions.goCustom; XyChartNETCtl1.Gradient.StartColor = Color.AliceBlue; XyChartNETCtl1.Gradient.EndColor = Color.SteelBlue; XyChartNETCtl1.Gradient.Orientation = XYChartNet.XYChartNETCtl.OrientationOptions.ooVertical; XyChartNETCtl1.Plot.Border.LineWidth = XYChartNet.XYChartNETCtl.WidthOptions.woOnePoint; XyChartNETCtl1.Plot.Border.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loCustom; XyChartNETCtl1.Plot.Border.LineColor = Color.Black; // Format grid lines XyChartNETCtl1.get_XAxis(0).Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_XAxis(0).Grid.LineColor = Color.Green; XyChartNETCtl1.get_YAxis(0).Grid.LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_YAxis(0).Grid.LineColor = Color.Green; // X Scale XyChartNETCtl1.get_XAxis(0).Scale.LabelColor = Color.Black; XyChartNETCtl1.get_XAxis(0).Scale.TicksColor = Color.Black; XyChartNETCtl1.get_XAxis(0).Scale.FormatStyle = XYChartNet.XYChartNETCtl.FormatStyles.fsDateTime; XyChartNETCtl1.get_XAxis(0).Scale.DateTimeFormat = "yy"; XyChartNETCtl1.get_XAxis(0).Scale.Label = ""; // Y Scale 0 XyChartNETCtl1.get_YAxis(0).Scale.Visible = true; XyChartNETCtl1.get_YAxis(0).Scale.LabelColor = Color.Black; XyChartNETCtl1.get_YAxis(0).Scale.TicksColor = Color.Black; XyChartNETCtl1.get_YAxis(0).Scale.LabelVertical = "Average Sales Price"; XyChartNETCtl1.get_YAxis(0).Scale.LabelVerticalFont = myFont2; // Format Profile 0 XyChartNETCtl1.get_Profile(0).Label = "Recession"; XyChartNETCtl1.get_Profile(0).YScale = 0; XyChartNETCtl1.get_Profile(0).NumSamples = 8; XyChartNETCtl1.get_Profile(0).MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_Profile(0).LineOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_Profile(0).ChartFeatureType = XYChartNet.XYChartNETCtl.ChartFeatureOptions.cfRecession; XyChartNETCtl1.get_Profile(0).FillEnabled = true; XyChartNETCtl1.get_Profile(0).FillColor = Color.Red; XyChartNETCtl1.get_Profile(0).RecessionLimitsMode = XYChartNet.XYChartNETCtl.RecessionModes.rmAuto; XyChartNETCtl1.get_Profile(0).DisplayInLegend = false; // Format Profile 1 XyChartNETCtl1.get_Profile(1).Label = "Ottawa"; XyChartNETCtl1.get_Profile(1).YScale = 0; XyChartNETCtl1.get_Profile(1).NumSamples = 27; XyChartNETCtl1.get_Profile(1).LineColor = Color.Blue; XyChartNETCtl1.get_Profile(1).MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_Profile(1).DisplayInLegend = true; // Format Profile 2 XyChartNETCtl1.get_Profile(2).Label = "Toronto"; XyChartNETCtl1.get_Profile(2).YScale = 0; XyChartNETCtl1.get_Profile(2).NumSamples = 17; XyChartNETCtl1.get_Profile(2).LineColor = Color.Green; XyChartNETCtl1.get_Profile(2).MarkerOption = XYChartNet.XYChartNETCtl.LineOptions.loNone; XyChartNETCtl1.get_Profile(2).DisplayInLegend = true; // Feed the data for each Profile XyChartNETCtl1.set_ProfileData(0, DataArray); XyChartNETCtl1.set_ProfileData(1, DataOttawa); XyChartNETCtl1.set_ProfileData(2, DataToronto); XyChartNETCtl1.Refresh(); }
Display