In this mode you're responsible to feed the data displayed by the legend. The following code switches the legend mode to manual:
C# |
Copy Code
|
---|---|
legend.Mode = LegendMode.Manual; |
Visual Basic |
Copy Code
|
---|---|
legend.Mode = LegendMode.Manual |
Feeding data to the legend is easy. You have to create an instance of the NLegendItemCellData class and add it to legend.Data.Items collection:
C# |
Copy Code
|
---|---|
NLegendItemCellData legendItemCellData = new NLegendItemCellData(); legendItemCellData.Text = "My First Legend Item"; legendItemCellData.MarkFillStyle = new NColorFillStyle(Color.Azure); legendItemCellData.MarkShape = LegendMarkShape.Star; legend.Data.Items.Add(legendItemCellData); |
Visual Basic |
Copy Code
|
---|---|
Dim legendItemCellData As New NLegendItemCellData legendItemCellData.Text = "My First Legend Item" legendItemCellData.MarkFillStyle = New NColorFillStyle(Color.Azure) legendItemCellData.MarkShape = LegendMarkShape.Star legend.Data.Items.Add(legendItemCellData) |
The NLegendItemCellData exposes properties allowing you to configure the item appearance. The mark style is controlled with the help of the MarkShape property accepting 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 from the MarkFillStyle property accepting styles that derive from the NFillStyle class.
When you have line charts you may want to use the mark item line style and disable the shape. For instance:
C# |
Copy Code
|
---|---|
NLegendItemCellData item = new NLegendItemCellData(); item.Text = "Custom legend item"; item.MarkShape = LegendMarkShape.None; item.MarkLineStyle.Width = new NLength(2, NGraphicsUnit.Pixel); item.MarkLineStyle.Color = Color.Red; legend.Data.Items.Add(item); |
Visual Basic |
Copy Code
|
---|---|
Dim item As New NLegendItemCellData item.Text = "Custom legend item" item.MarkShape = LegendMarkShape.None item.MarkLineStyle.Width = New NLength(2, NGraphicsUnit.Pixel) item.MarkLineStyle.Color = Color.Red legend.Data.Items.Add(item) |
The TextStyle property controls the text style used to display the legend data item text:
C# |
Copy Code
|
---|---|
item.TextStyle.FontStyle = new NFontStyle("Arial", 13); |
Visual Basic |
Copy Code
|
---|---|
item.TextStyle.FontStyle = New NFontStyle("Arial", 13) |