MindFusion.Charting for Silverlight Programmer's Guide
Legend

There are no limits as to the count of legend you can add to the chart. They must be added to the Chart.Legends property. MindFusion.Gauges for Silverlight supports two types of legends.

Chart Legend

ChartLegend takes its labels from the ChartSeries.Title property of the ChartSeriesCollection it refers to. Use ChartLegend.Series to set the ChartSeriesCollection. The brushes for the rectangles that are drawn before each label are taken automatically from ChartSeries.Fills. If a given ChartSeries has more than brushes in its Fills property, the first brush is taken.

Here is a sample code that creates a ChartLegend that is bound to the Series collection of the chart.

C#  Copy Code

ChartLegend legend = new ChartLegend();
legend.Series = barChart1.Series;
legend.BorderBrush = Brushes.LightGray;
legend.Background = Brushes.White;           
barChart1.Legends.Add(legend);

VB.NET  Copy Code

Dim legend As New ChartLegend()
legend.Series = barChart1.Series
legend.BorderBrush = Brushes.LightGray
legend.Background = Brushes.White
barChart1.Legends.Add(legend)

Series Legend

SeriesLegend is designed to give details about data in a single ChartSeries. Its labels and brushes are custom-set with the SeriesLegend.LabelsSource and SeriesLegend.BrushesSource properties.

Here is a sample code that creates a SeriesLegend with two brushes and two labels:

C#  Copy Code

SeriesLegend legend1 = new SeriesLegend();
legend1.BrushesSource = new List<Brush>() {
    new SolidColorBrush(Color.FromArgb(100, 0, 255, 0)),
    Brushes.Yellow };
legend1.BorderBrush = Brushes.Silver;
legend1.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
legend1.LabelsSource = new List<string>() { "Arina LLC", "Falderia Corp." };
lineChart1.Legends.Add(legend1);

VB.NET  Copy Code

Dim legend1 As New SeriesLegend()
legend1.BrushesSource = New List(Of Brush)() From { _
    New SolidColorBrush(Color.FromArgb(100, 0, 255, 0)), _
    Brushes.Yellow _
}
legend1.BorderBrush = Brushes.Silver
legend1.Background = New SolidColorBrush(Color.FromRgb(240, 240, 240))
legend1.LabelsSource = New List(Of String)() From { _
    "Arina LLC", _
    "Falderia Corp." _
}
lineChart1.Legends.Add(legend1)

Customizing the Legend's Appearance

The following properties are used to customize how the legend looks:

Position of the Legend

You can place the legend anywhere around the plot area where the chart is drawn. The docking of the legend is set with the Dock attached property of the LayoutPanel, which contains both the chart and the legend. The alignment of the legend depends on its position: if its docked to the bottom or the top of the plot area, the alignment is set with the HorizontalAlignment. If the legend is placed at the left or right side of the plot area, its alignment is set with VerticalAlignment.

Here is sample code that palces a legend to the right of the plot area and algns it in the middle:

C#  Copy Code

LayoutPanel.SetDock(legend, Dock.Right);
legend.VerticalAlignment = VerticalAlignment.Top;

VB.NET  Copy Code

LayoutPanel.SetDock(legend, Dock.Right)
legend.VerticalAlignment = VerticalAlignment.Top

A diagram of the legend classes.