本示例演示了在运行时刻如何访问并定制图表的 图例。
要控制图例中是否显示系列、指标线、常数线 和 数值带,则使用它们的 SeriesBase.ShowInLegend、Indicator.ShowInLegend、ConstantLine.ShowInLegend 和 Strip.ShowInLegend 属性。
C# | 复制代码 |
---|---|
Legend legend = chartControl1.Legend; // Display the chart control's legend. legend.Visible = true; // Define its margins and alignment relative to the diagram. legend.Margins.All = 8; legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside; legend.AlignmentVertical = LegendAlignmentVertical.Top; // Define the layout of items within the legend. 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; // Define the limits for the legend to occupy the chart's space. legend.MaxHorizontalPercentage = 50; legend.MaxVerticalPercentage = 50; // Customize the legend appearance. 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; // Customize the legend text properties. legend.Antialiasing = false; legend.Font = new Font("Arial", 9, FontStyle.Bold); legend.TextColor = Color.DarkBlue; |
Visual Basic | 复制代码 |
---|---|
Dim legend As Legend = chartControl1.Legend ' Display the chart control's legend. legend.Visible = True ' Define its margins and alignment relative to the diagram. legend.Margins.All = 8 legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside legend.AlignmentVertical = LegendAlignmentVertical.Top ' Define the layout of items within the legend. 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 ' Define the limits for the legend to occupy the chart's space. legend.MaxHorizontalPercentage = 50 legend.MaxVerticalPercentage = 50 ' Customize the legend appearance. 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 ' Customize the legend text properties. legend.Antialiasing = False legend.Font = New Font("Arial", 9, FontStyle.Bold) legend.TextColor = Color.DarkBlue |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1373。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |