Each ChartArea may provide a legend box. The legend box is represented by the LegendBox class which contains different properties to set up its appearance.
Setting a Background
LegendBox background might either be represented by a background color or a background image.
To set a solid background color, use the BackColor property. To set a gradient background color, set the GradientType property to a value different from GradientType.None and use the GradientBackColor property.
To set the background image, use the BackImage property which accepts a BackImage object briefly described in WorkingWithChartAreas.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=24
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=4
Setting a Font
To set the legend items font, use the Font property. To set the legend items font color, use the FontColor property.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=37
Setting a Border
LegendBox may show a border which look is controlled by the following properties:
- BorderColor gets or sets the border color.
- BorderWidth gets or sets the border width in pixels; the default value is 1 pixel.
- BorderStyle gets or sets the border style.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=24
Setting a Position
The legend box position is specified by the LegendPositionType property. Its default value is LegendPositionType.Right. You can also set a custom legend box position. To do it, set LegendPositionType to LegendPositionType.Custom and set the Position property as appropriate.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=10
Setting a Layout
Aspose.Chart provides different types of the legend box layout. This is controlled by the LayoutType property. The default value is LayoutType.Column. You can also specify custom number of the legend items columns and rows by setting the ColumnCount and RowCount properties.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=10
Setting a Type
Aspose.Chart allows to place the legend box inside or outside of the chart area. You can specify this using the LegendBoxType property. By default, the legend box is drawn outside the chart area.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=10
Setting a Type of the Items
You can specify how legend items are created inside the legend box (whether they created by points, by series, or by default) using the LegendItemsType property.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=83
Controlling Visibility
You can make the legend box visible or not using its IsVisible property.
Example
http://www.aspose.com/Products/Aspose.Chart/Demos/CodeChart.aspx?GalleryItemId=1
Code Sample
[C#]
LegendBox legendBox = chartArea.LegendBox;
// Setting gradient background color
legendBox.GradientType = GradientType.HorizontalCenter;
legendBox.GradientBackColor = Color.Cornsilk;
// Setting border
legendBox.BorderColor = Color.Bisque;
legendBox.BorderWidth = 3;
// Setting position
legendBox.LegendPositionType = LegendPositionType.Right;
// Setting layout
legendBox.LayoutType = LayoutType.TableVertical;
// Setting type
legendBox.LegendBoxType = LegendBoxType.OutsideChartArea;
// Setting items type
legendBox.LegendItemsType = LegendItemsType.BySeries;
[VB .NET]
Dim legendBox As LegendBox = chartArea.LegendBox
' Setting gradient background color
legendBox.GradientType = GradientType.HorizontalCenter
legendBox.GradientBackColor = Color.Cornsilk
' Setting border
legendBox.BorderColor = Color.Bisque
legendBox.BorderWidth = 3
' Setting position
legendBox.LegendPositionType = LegendPositionType.Right
' Setting layout
legendBox.LayoutType = LayoutType.TableVertical
' Setting type
legendBox.LegendBoxType = LegendBoxType.OutsideChartArea
' Setting items type
legendBox.LegendItemsType = LegendItemsType.BySeries