Version

Customize Chart Legends

This topic provides an overview of how to customize the legends in the Chart control.

The location of the chart’s legend can be set to either on the top, bottom, right, or left of the chart. A combination of the Margins and SpanPercentage properties is used to size the legend and eliminate any extra space. For example, if a legend is displayed to the right of the chart and only contains four items: the top margin and the bottom margin can be increased to shorten the height of the legend. The SpanPercentage in this case could be used to lessen the width of the legend.

  1. Before you start writing any code, you should place using/import directives in your code-behind so you don’t need to always type out a member’s fully qualified name.

In Visual Basic:

Imports Infragistics.UltraChart.Shared.Styles

In C#:

using Infragistics.UltraChart.Shared.Styles;
  1. The following code illustrates how to set the position of the legend and adjust its size using the margins and the SpanPercentage property:

In Visual Basic:

Me.UltraChart1.Legend.Visible = True
Me.UltraChart1.Legend.Location = LegendLocation.Right
Me.UltraChart1.Legend.Margins.Left = 5
Me.UltraChart1.Legend.Margins.Right = 10
Me.UltraChart1.Legend.Margins.Top = 15
Me.UltraChart1.Legend.Margins.Bottom = 90
Me.UltraChart1.Legend.SpanPercentage = 15

In C#:

this.ultraChart1.Legend.Visible = true;
this.UltraChart1.Legend.Location = LegendLocation.Right;
this.UltraChart1.Legend.Margins.Left = 5;
this.UltraChart1.Legend.Margins.Right = 10;
this.UltraChart1.Legend.Margins.Top = 15;
this.UltraChart1.Legend.Margins.Bottom = 90;
this.UltraChart1.Legend.SpanPercentage = 15;
  1. The appearance of the legend can also be customized. The colors can be changed using the BackgroundColor , and FontColor properties. The BorderThickness , BorderStyle , and AlphaLevel properties can also be used to modify the appearance. The following code illustrates how to set various formatting attributes for the legend:

In Visual Basic:

Me.UltraChart1.Legend.BackgroundColor = System.Drawing.Color.Yellow
Me.UltraChart1.Legend.FontColor = System.Drawing.Color.Blue
Me.UltraChart1.Legend.BorderColor = System.Drawing.Color.Red
Me.UltraChart1.Legend.BorderStyle = LineDrawStyle.Dash
Me.UltraChart1.Legend.BorderThickness = 3
Me.UltraChart1.Legend.AlphaLevel = 25

In C#:

this.UltraChart1.Legend.BackgroundColor = System.Drawing.Color.Yellow;
this.UltraChart1.Legend.FontColor = System.Drawing.Color.Blue;
this.UltraChart1.Legend.BorderColor = System.Drawing.Color.Red;
this.UltraChart1.Legend.BorderStyle = LineDrawStyle.Dash;
this.UltraChart1.Legend.BorderThickness = 3;
this.UltraChart1.Legend.AlphaLevel = 25;