In This Topic
The NLegend object derives from the NWidget base class and as such has all properties that are common for widgets - background fill, margins, padding, border, etc. The legend builds on top of that to provide support for gridlines and interlace styles.
Setting the Legend Background Fill
You set the legend background fill through the BackgroundFill property - the following code snippet modifes the legend background fill to semitransparent white:
C# |
Copy Code
|
legend.BackgroundFill = new NColorFill(NColor.FromColor(NColor.White, 0.5f));
|
The legend grid lines visually separate the data items horizontally and vertically. You control the appearance of horizontal and vertical grid lines through the HorizontalGridStroke and VerticalGridStroke properties. The following code shows how to change the horizontal grid lines to thick solid black:
C# |
Copy Code
|
legend.HorizontalGridStroke = new NStroke(2, NColor.Black);
|
Legend Interlace Styles
The legend interlace stripes are automatically generated based on the interlace styles added to the InterlaceStyles collection of the legend. Each interlace style is represented by a NLegendInterlaceStyle object controlling the interlace stripes appearance and orientation (row / column). Furthermore, the interlace stripes have Z order - stripes generated by interlace styles on top of the collection appear below interlace stripes generated by the styles afterward. The following code creates a row and column interlace style:
C# |
Copy Code
|
NLegendInterlaceStylesCollection interlaceStyles = new NLegendInterlaceStylesCollection();
NLegendInterlaceStyle horzInterlaceStyle = new NLegendInterlaceStyle();
horzInterlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.LightBlue, 0.5f));
horzInterlaceStyle.Type = ENLegendInterlaceStyleType.Row;
horzInterlaceStyle.Length = 1;
horzInterlaceStyle.Interval = 1;
interlaceStyles.Add(horzInterlaceStyle);
NLegendInterlaceStyle vertInterlaceStyle = new NLegendInterlaceStyle();
vertInterlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.DarkGray, 0.5f));
vertInterlaceStyle.Type = ENLegendInterlaceStyleType.Col;
vertInterlaceStyle.Length = 1;
vertInterlaceStyle.Interval = 1;
interlaceStyles.Add(vertInterlaceStyle);
legend.InterlaceStyles = interlaceStyles;
|
See Also