Xceed Chart for WinForms v4.4 Documentation
Feeding Custom Data

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Legends > Feeding Custom Data

Xceed Chart for WinForms' integrated legend can operate in three modes: Disabled, Automatic, and Manual (for more details, see LegendMode Enumeration). In disabled mode the legend is not displayed. When you set the mode to Automatic, the legend data is supplied by the series of the charts associated with the legend. In this case, you control the displayed legend data items through the SeriesLegend object. For more information, consult the Legend topic in the Series Attributes book. 

This topic describes how to feed data to a legend when you set the legend mode to Manual:

VB.NET  
legend.Mode = LegendMode.Manual

C#  
legend.Mode = LegendMode.Manual;

Each legend's data item is represented by a LegendDataItem. The following code adds a new data item:

VB.NET  

Dim item As LegendDataItem = New LegendDataItem()
item.Text = "Custom legend item"
item.MarkFillEffect.SetGradient(GradientStyle.Horizontal,
GradientVariant.Variant1, Color.Azure, Color.Blue)
item.MarkShape = LegendMarkShape.Rectangle
legend.Data.Items.Add(item)
C#  
LegendDataItem item = new LegendDataItem();
item.Text = "Custom legend item";
item.MarkFillEffect.SetGradient(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Azure, Color.Blue);
item.MarkShape = LegendMarkShape.Rectangle;
legend.Data.Items.Add(item);

The LegendDataItem object exposes several properties that allow you to configure the item's appearance. The mark style is controlled with the MarkShape property, which accepts values from the LegendMarkShape enumeration. The following table shows the possible mark shapes: 

Rectangle Circle Diamond Triangle
Inverted Triangle Cross Diagonal Cross Star

The filling of the mark is controlled with the MarkFillEffect property, which returns a reference to a FillEffect object. 

When you have line charts showing trends, you may want to use the mark item line properties and disable the shape. For instance:

VB.NET  

item = New LegendDataItem()

item.Text = "Custom legend item"
item.MarkShape = LegendMarkShape.None
item.LineProps.Width = 2
item.LineProps.Color = Color.Red
legend.Data.Items.Add(item)

legend.Data.TextOffset = 5
C#  
item = new LegendDataItem();

item.Text = "Custom legend item";
item.MarkShape = LegendMarkShape.None;
item.LineProps.Width = 2;
item.LineProps.Color = Color.Red;
legend.Data.Items.Add(item);

legend.Data.TextOffset = 5;

The last line of the example above instructs the legend that texts in the legend item should be 5 pixels away from the area reserved for the mark or line. The Text property controls the text displayed by the legend's data item. By default it is blank. 

Some of the legend's mark properties cannot be configured individually. These are mark size, text properties (font, backplane, etc), text offset, and cell inflate. These properties are common for all data items and are controlled from the LegendData object:

VB.NET  

legend.Data.MarkSize = 10
legend.Data.TextProps.Font = New Font("Arial", 13)
C#  
legend.Data.MarkSize = 10;
legend.Data.TextProps.Font = new Font("Arial", 13);

Related Examples

Windows Forms: Legend\General 

Web forms: Legend\General

See Also

Layout and Position | LegendData | LegendDataItem | FillEffect | ChartText