This example demonstrates how a chart's Legend can be accessed and customized at runtime.
To control whether series, Indicators, Constant Lines and Strips should be shown in the legend, use their SeriesBase.ShowInLegend, Indicator.ShowInLegend, ConstantLine.ShowInLegend and Strip.ShowInLegend properties.
C# |
Legend legend = chartControl1.Legend;
legend.Visible = true;
legend.Margins.All = 8;
legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
legend.AlignmentVertical = LegendAlignmentVertical.Top;
legend.Direction = LegendDirection.LeftToRight;
legend.EquallySpacedItems = true;
legend.HorizontalIndent = 8;
legend.VerticalIndent = 8;
legend.TextVisible = true;
legend.TextOffset = 8;
legend.MarkerVisible = true;
legend.MarkerSize = new Size(20, 20);
legend.Padding.All = 4;
legend.MaxHorizontalPercentage = 50;
legend.MaxVerticalPercentage = 50;
legend.BackColor = Color.Beige;
legend.FillStyle.FillMode = FillMode.Gradient;
((RectangleGradientFillOptions)legend.FillStyle.Options).Color2 = Color.Bisque;
legend.Border.Visible = true;
legend.Border.Color = Color.DarkBlue;
legend.Border.Thickness = 2;
legend.Shadow.Visible = true;
legend.Shadow.Color = Color.LightGray;
legend.Shadow.Size = 2;
legend.Antialiasing = false;
legend.Font = new Font("Arial", 9, FontStyle.Bold);
legend.TextColor = Color.DarkBlue;
|
VB |
Dim legend As Legend = chartControl1.Legend
legend.Visible = True
legend.Margins.All = 8
legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside
legend.AlignmentVertical = LegendAlignmentVertical.Top
legend.Direction = LegendDirection.LeftToRight
legend.EquallySpacedItems = True
legend.HorizontalIndent = 8
legend.VerticalIndent = 8
legend.TextVisible = True
legend.TextOffset = 8
legend.MarkerVisible = True
legend.MarkerSize = New Size(20, 20)
legend.Padding.All = 4
legend.MaxHorizontalPercentage = 50
legend.MaxVerticalPercentage = 50
legend.BackColor = Color.Beige
legend.FillStyle.FillMode = FillMode.Gradient
CType(legend.FillStyle.Options, RectangleGradientFillOptions).Color2 = Color.Bisque
legend.Border.Visible = True
legend.Border.Color = Color.DarkBlue
legend.Border.Thickness = 2
legend.Shadow.Visible = True
legend.Shadow.Color = Color.LightGray
legend.Shadow.Size = 2
legend.Antialiasing = False
legend.Font = New Font("Arial", 9, FontStyle.Bold)
legend.TextColor = Color.DarkBlue
|