1. There are no limits as to the count of legend you can add to the chart. Charting for WPF supports two types of legends.
1.1 ChartLegend takes its labels from the Title property of the ChartSeries it refers to. The brushes for the rectangles that are drawn before each label are taken from the Fills property of the ChartSeries. The series are set with the Series property.
Here is a sample code that creates a ChartLegend:
C# Copy Code |
---|
ChartLegend legend = new ChartLegend(); |
VB.NET Copy Code |
---|
Dim legend As New ChartLegend() |
1.2 SeriesLegend is designed to give details about data in a single ChartSeries. Its labels and brushes are set with LabelsSource and BrushesSource properties.
Here is a sample code that creates a SeriesLegend with two brushes and two labels:
C# Copy Code |
---|
SeriesLegend legend1 = new SeriesLegend(); |
VB.NET Copy Code |
---|
Dim legend1 As New SeriesLegend() |
2. Both types of legend descend from the Legend class and expose its style properties:
3. 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 places a legend to the right of the plot area and aligns it in the middle:
C# Copy Code |
---|
LayoutPanel.SetDock(legend, Dock.Right); |
VB.NET Copy Code |
---|
LayoutPanel.SetDock(legend, Dock.Right) |
Diagram of the Legend classes.